I cannot understand what is going on with my code: why I get a “no matching function for call to push_back” error. I can only guess it is a newby mistake…
int main(){
typedef std::tr1::shared_ptr<Base> Base_p;
typedef std::vector<Base_p> VectorPointers_t;
std::tr1::shared_ptr<Derived> myDer01(Derived);
VectorPointers_t myVector = VectorPointers_t();
myVector.push_back(myDer01);
}
Try this:
There is a big error in your code: The line declaring
myDer01actually declares a function and not a a variable. But even if you had written(Derived())instead ofDerivedit would have been wrong, since you cannot construct a shared pointer from an object — only from a pointer! So you really want to saynew Derived.