Reputation: 125
#include "boost\shared_ptr.hpp"
class A{
public:
A(){}
~A(){}
};
int main()
{
boost::shared_ptr<A> ptrA;
ptrA(new A);
}
I would like to know why this code won't compile? I want to know the difference if I just use
boost::shared_ptr<A> ptrA(new A);?
Upvotes: 1
Views: 45252
Reputation: 31972
boost::shared_ptr<A> ptrA(new A);
Calls conversion constructor which converts A*
into the shared_ptr
. This is a default way to construct the ptr.
ptrA(new A);
Calls operator()
. This is used for a lot of reasons, one being to make objects emulate functions, i.e functors. But this is not used with shared_ptr
.
The constructor exists, operator()
doesnt.
Upvotes: 4