请问有人能解释一下为什么我在这里会收到编译错误 - 错误C2558:类'std::auto_ptr<_Ty>':没有可用的复制构造函数或复制构造函数被声明为'explicit'。
#include <memory>
#include <vector>
#include <string>
template<typename T>
struct test
{
typedef std::auto_ptr<T> dataptr;
typedef std::auto_ptr< test<T> > testptr;
test( const T& data ):
data_( new T(data) )
{
};
void add_other( const T& other )
{
others_.push_back( testptr( new test(other) ) );
}
private:
dataptr data_;
std::vector< testptr > others_;
};
int main(int argc, char* argv[])
{
test<std::string> g("d");
//this is the line that causes the error.
g.add_other("d");
return 0;
}
g = test<std::string>("d");
,对吧? - Jesse Jashinsky