B
Bit byte
I have a base (abstract) class with a public method foo delared as:
virtual BaseClass* foo(..)=0;
I wnat to derive two classes A and B from Baseclass so that I return a
pointer for A and B respectively (i.e. A::foo() returns a A*, and
B::foo() returns a B*).
I notice that if I declare the foo in A and B like this:
A* A::foo(...);
B* B::foo(...);
The compiler barfs. I am thinking of doing the ff:
1). leave the signature unchanged (ie. BaseClass* A::foo(), BaseClass*
B::foo()
2). Create the appropriate pointer in the method and then return it as a
BaseClass*.
I have two questions:
1). Is this the correct way to do this?
2). Can I overload AND overide a function (i.e. can A::foo() take
different arguments?)
virtual BaseClass* foo(..)=0;
I wnat to derive two classes A and B from Baseclass so that I return a
pointer for A and B respectively (i.e. A::foo() returns a A*, and
B::foo() returns a B*).
I notice that if I declare the foo in A and B like this:
A* A::foo(...);
B* B::foo(...);
The compiler barfs. I am thinking of doing the ff:
1). leave the signature unchanged (ie. BaseClass* A::foo(), BaseClass*
B::foo()
2). Create the appropriate pointer in the method and then return it as a
BaseClass*.
I have two questions:
1). Is this the correct way to do this?
2). Can I overload AND overide a function (i.e. can A::foo() take
different arguments?)