I hope you can see what I'm trying to achieve because I can't come up with the words :)
#include <vector>
using namespace std;
class A {};
class B : public A {};
template <typename T>
class Response
{
private:
T t;
};
int main()
{
vector<Response<A> > names;
Response<A> heman;
names.push_back(heman);
Response<B> hellman;
names.push_back(hellman); // nogo!!
return 0;
}
Everything works except the second push_back. The point is to have a container (e.g. vector)
which holds template objects. The template parameter is the superclass and the objects
are either of the superclass or its descendants.
Can it be done?
Edited by denarced, 03 November 2011 - 03:16 AM.


Sign In
Create Account


Back to top









