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"
#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()
不存在。
相关文章:
- Usages of std::move
- 为什么 std::optional::operator=(U&&) 要求你是非标量类型?
- 'operator='已弃用:改用 QDir::setPath()
- 使用 [] 运算符时"binding reference of type discards qualifiers"
- 如何处理 c++ 中类实现中的"invalid use of non-static data member"?
- 过载'operator new'如何导致无限循环?
- 具有变量Number of Arguments的std::函数的矢量
- Capacity of a deque
- Deprecation of _writeBarrier()
- constexpr begin of a std::array
- C++ "error: use of overloaded operator '*' is ambiguous"似乎只有一场比赛
- 使用 operator[] 访问私有 std::map of unique_ptr
- QList::operator[]中的断言失败<T>:QJoysticks 中的"index out of range"
- 为什么我会得到"Invalid use of :: (scope resolution operator)?"
- QList<T>::operator[]: "index out of range" 中的断言失败
- 对简单的帐户检查程序有问题?程序返回编译错误,指出"no match for 'operator||' unsure of how to fix?"
- 有关 C 和 C++ 中的"Address-of operator" (&) 和数组的问题
- shared_ptr : "call of an object of a class type without appropriate operator() or conversion functio
- Inheritance of operator()
- 如何调试提升元组错误"no operator found which takes a left-hand operand of type"