#include <iostream>
#include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp>
using namespace std;
struct Node
{
Node(int data, boost::shared_ptr<int> next = boost::make_shared<int>())
: m_data(data), m_next(next) {}
int m_data;
boost::shared_ptr<int> m_next;
};
错误: http: //www.compileonline.com/compile_cpp11_online.php - 在线编译和执行 C++11(GNU GCC 版本 4.7.2)
Compiling the source code....
$g++ -std=c++11 main.cpp -o demo -lm -pthread -lgmpxx -lgmp -lreadline 2>&1
main.cpp: In constructor 'Node::Node(int, boost::shared_ptr)':
main.cpp:9:34: error: use of deleted function 'boost::shared_ptr::shared_ptr(const boost::shared_ptr&)'
In file included from /usr/include/boost/shared_ptr.hpp:17:0,
from main.cpp:2:
/usr/include/boost/smart_ptr/shared_ptr.hpp:168:25: note: 'boost::shared_ptr::shared_ptr(const boost::shared_ptr&)' is implicitly declared as deleted because 'boost::shared_ptr' declares a move constructor or move assignment operator
问题> 我看到了Using std::shared_ptr with clang++ and libstdc++的帖子。但是,我不知道如何解决它。
该问题中发布的解决方案是“将默认复制构造函数和复制赋值运算符添加到 shared_ptr 将解决问题。”