[英]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
. 调用将
A*
转换为shared_ptr
转换构造函数。 This is a default way to construct the ptr. 这是构造ptr的默认方法。
ptrA(new A);
Calls operator()
. 调用
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
. 但这不与
shared_ptr
。
The constructor exists, operator()
doesnt. 构造函数存在,
operator()
不存在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.