I have two classes, one derived from the other, and a virtual get function is supposed to return a pointer to a container with different element types depending on who's getting called. Simplified:
Code:
class A {
public:
virtual stl_container<T1>* get_something();
};
class B : public A {
public:
stl_container<T2>* get_something();
};
And no, the classes themselves are not templates.
Anyway, when I try to compile this, it gives me an error message about "invalid covariant return types." So I thought it might help if the containers were recast into an isa relationship or something:
Code:
template <typename C = T1>
class C1 : public stl_container<C> {};
class C2 : public C1<T2> {};
class A {
public:
virtual C1<>* get_something();
};
class B : public A {
public:
C2* get_something();
};
But that didn't work either.
I'm almost tempted to return a void* and cast it as it comes out. Is there another solution?
Oh, the reason the simplest solution (turning class A and B into a templated class) is not possible because the T1, T2 types are custom classes and different things are supposed to happen to them depending on the class.