Val
Val

Reputation: 209

boost shared_ptr and derived class

I have such a code:

class Base { ... };

class Derived : public Base
{ ... };

boost:shared_ptr<Base> p;

int main()
{
  p(new Derived);
 ...
}

It seems to me that this isn't working. What am I missing?

Upvotes: 0

Views: 299

Answers (1)

David G
David G

Reputation: 96845

You're confusing in class initialization with assignment. The member-initializer list syntax only works inside of the class body:

p = boost::make_shared<Derived>();

Upvotes: 2

Related Questions