oop - Function overloading with the only change in "uint32_t" & uint64_t" in pure virtual function in c++ -
i've pair pure virtual function defined inside c++ class, i've overloaded. code snippet below::
virtual uint64_t abc::getvalue()=0; virtual uint32_t abc::getvalue()=0;
here, difference in function signature return type of getval() "uint32_t
" & "uint64_t
"..
it's throwing compilation error can't overloaded.
plz me on this.
you can't overload based on return type, on parameter types. because overload chosen based on how function called, , function call doesn't specify expected return type.
options include:
- give functions different names;
- "return" value via reference parameter, rather return value;
- add dummy parameter, different type each version, specify return type;
- return "proxy" object that's convertible either type (although means you'll have single function, derived classes can't override 2 versions separately).
Comments
Post a Comment