shared_ptr : "call of an object of a class type without appropriate operator() or conversion functio

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

本文关键字:of operator appropriate without functio conversion or type ptr call shared      更新时间:2023-10-16
#include "boostshared_ptr.hpp"
class A{
public:
A(){}
~A(){}
};
int main()
{
    boost::shared_ptr<A> ptrA;
    ptrA(new A); 
}

我想知道为什么这段代码无法编译?我想知道如果我只使用

boost::shared_ptr<A> ptrA(new A);?
boost::shared_ptr<A> ptrA(new A);

调用转换构造函数,该构造函数将A*转换为shared_ptr。这是构造 ptr 的默认方法。

ptrA(new A); 

呼叫operator() .使用它有很多原因,一个是使对象模拟函数,即函子。但这不用于shared_ptr.

构造函数存在,operator()不存在。