#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;
};
Error:
http://www.compileonline.com/compile_cpp11_online.php
- Compile and Execute C++11 Online (GNU GCC version 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
Question> I have see the post Using std::shared_ptr with clang++ and libstdc++. However, I don't know how to fix it.
The solution posted in that question is "Adding a defaulted copy constructor and copy assignment operator to shared_ptr will fix the problem."
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…