Because the real situation is more like
Code:
class Screen
{
std::vector<Thingy *> v;
public:
void add(Thingy & t)
{
v.push_back(new Thingy(t));
}
};
Because I don't want clients to have to use new. So instead, I figured I could solve this with a template function. But I'm getting errors still. I make the member functiona add a template
screen.h
Code:
template <typename T> void add(const T & t);
screen.cpp
Code:
template <typename T> void Screen::add(const T& t)
{
v.push_back(new T(t));
update();
}
But like, problems:
1) I get a linker error saying that I have undefined references to the add function. Do I put the definition of the function in the header since templates are like 'supermacros' that need wierd instantiating or something?
2) Do I just hope that the user isn't stupid and passes something that is derived from Thingy? It'll definitely do wierd things if it isn't.