1

The below code is working fine:

scoped_ptr<clsA> pclObjA(new clsA());

But the below statements are not working:

scoped_ptr<clsA> pclObjA;

// some statements

pclObjA(new clsA());

I am getting compilation error like below:

error: no match for call to ‘(boost::scoped_ptr<clsA>) (clsA*)’

Please help me to solve this issue.

Additional Info: the clsA derived from claX

hmjd
  • 120,187
  • 20
  • 207
  • 252
sokid
  • 813
  • 3
  • 10
  • 16

1 Answers1

2

The code:

pclObjA(new clsA());

does not invoke the constructor (and the scoped_ptr<> instance already exists anyway), but is attempting to invoke a function call operator with signature scoped_ptr<clsA>::operator()(clsaA*) which does not exist.

Use boost::scoped_ptr<T>::reset(T*) to assign a dynamically allocated object after construction:

pclObjA.reset(new clsA());
hmjd
  • 120,187
  • 20
  • 207
  • 252