#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);?
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, ie functors. But this is not used with shared_ptr
.
The constructor exists, operator()
doesnt.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.