简体   繁体   English

shared_ptr:“在没有适当的operator()或将函数转换为指针到函数的类型的情况下,调用类类型的对象”

[英]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.

相关问题 指向函数的指针是函数对象类型吗? - Is a pointer-to-function is a function object type? 使用指向 B 的成员 function 中的 class B 的指针初始化 class A 的std::shared_ptr 类型的成员 - Initializing a member with type std::shared_ptr<B> of a class A with a pointer to class B in a member function of B 没有适当的operator()的类类型的对象的调用 - call of an object of a class type without appropriate operator() std :: shared_ptr隐式转换为指针类型 - Implicit conversion of std::shared_ptr to pointer type 将shared_ptr作为参数传递给接受类类型对象的函数 - pass shared_ptr as a argument to a function which accepts object of a class type 检查指向函数类型的调用约定 - Check calling convention of pointer-to-function type boost :: python函数调用中boost :: shared_ptr的转换 - conversion of boost::shared_ptr in boost::python function call 如何使用std :: shared_ptr进行函数重载 <void> 和另一种类型的std :: shared_ptr? - How to do function overloading with std::shared_ptr<void> and another type of std::shared_ptr? 没有对象的对象的shared_ptr向量无法调用成员函数 - cannot call member function without object for vector of shared_ptr of object 使用shared_ptr将原始指针传递给函数 - Passing raw pointer to a function with shared_ptr
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM