相关疑难解决方法(0)

为什么auto_ptr构造不能使用= syntax

我遇到了一个对我没有多大意义的编译器错误:

#include <memory>
using namespace std;

auto_ptr<Table> table = db->query("select * from t");
Run Code Online (Sandbox Code Playgroud)

错误:从'Table*'转换为非标量类型'std :: auto_ptr <Table>'

但是,以下行确实有效:

auto_ptr<Table> table(db->query("select * from t"));
Run Code Online (Sandbox Code Playgroud)

这个构造函数的定义是什么阻止它像我期望的那样工作?我认为初始化声明使用了构造函数.

这是我auto_ptr的构造函数(来自SGI STL):

explicit
auto_ptr(element_type* __p = 0) throw() : _M_ptr(__p) { }
Run Code Online (Sandbox Code Playgroud)

c++ gcc stl auto-ptr

9
推荐指数
3
解决办法
3330
查看次数

标签 统计

auto-ptr ×1

c++ ×1

gcc ×1

stl ×1