I have the following code that does not compile.
class Base { public: virtual ~Base() { }; }; class Derived : public Base { }; class NotDerived { }; template <typename T> class Group { }; int main() { Group<Base> *g = NULL; g = new Group<Base>();
I understand that this does not compile because g is a different type than Group<Derived> . To make this work in Java, I would do something like Group<? extends Base> g Group<? extends Base> g , but C ++ does not have this keyword as far as I know. What can be done?
Edit: I would like to clarify that I do not want to be able to set types not derived from Base , like g . I updated my example to explain this.
Edit 2: There are two problems with my problem. Dave's I found it simple and easy to spot. But Bowie's (along with Mark's add-ons) were better suited to my needs.
Ryan
source share