I have a base class (let's say "Base") with a method returning a pointer to this class (let's say "Base *Base::Method (void)"). Then I also have a class derived from Base (let's call it "Derived").
How can I make Method() return Derived* instead of Base*? It's not automatically converted since I get a compilation error of the form "error: invalid conversion from `Base*` to `Derived*`.
The code would look like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
class Base {
...
public:
Base *Method (void);
...
};
class Derived : public Base {
...
};
int main () {
...
Derived example;
Derived *tmp = example.Method(); // THIS DOESN'T WORK!!!
return 0;
}