简体   繁体   中英

shared_ptr : “call of an object of a class type without appropriate operator() or conversion function to pointer-to-function type”

#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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM