[英]Function overloading with the only change in “uint32_t” & uint64_t" in pure virtual function in c++
I've a pair pure virtual function defined inside a c++ class, which I've overloaded. 我在c ++类中定义了一对纯虚函数,我已经重载了。 Code snippet below:: 下面的代码段:
virtual uint64_t Abc::GetValue()=0;
virtual uint32_t Abc::GetValue()=0;
Here, the only difference in function signature is the return type of GetVal() " uint32_t
" & " uint64_t
".. 在这里,函数签名的唯一区别是GetVal()的返回类型“ uint32_t
”和“ uint64_t
”。
It's throwing compilation error that this can't be overloaded. 抛出编译错误,该错误不能被重载。
Plz help me on this. 请帮助我。
You can't overload based on return type, only on parameter types. 您不能仅基于参数类型基于返回类型进行重载。 This is because the overload is chosen based on how the function is called, and a function call doesn't specify the expected return type. 这是因为根据函数的调用方式选择了重载,并且函数调用未指定预期的返回类型。
Options include: 选项包括:
In c++ onverloading is only done on the parameters of the function not on the return type . 在c ++中,onverloading仅在函数的参数上执行,而不在返回类型上执行 。 So your are redefining the same function which is an error. 因此,您正在重新定义相同的功能,这是一个错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.