我遇到了一个对我没有多大意义的编译器错误:
#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)