Suppose I have a base abstract class:
class Foo {
public:
struct FooStruct;
virtual FooStruct *DoFoo() = 0;
};
And now I would like to implement the DoFoo
in Bar
and also define the FooStruct
inside it:
class Bar: public Foo {
public:
struct FooStruct {
int data;
};
FooStruct *DoFoo() {
FooStruct *fs = new FooStruct;
fs->data = 42;
return fs;
}
};
However, g++
(in my case) recognizes Foo::FooStruct
and Bar::FooStruct
as two different structures and will complain about invalid covariant type ...
because I redefine return type of a method.
How can I fix this?