我从 Windows 移植了我的代码(它可以使用 MSVC 和 Intel 编译器很好地编译),但是当使用 GCC 4.8.1 时(在 GCC 4.7 中,我会收到一个内部编译器错误)我得到了这个令人讨厌的错误(对大小表示歉意)。有人可以帮帮我吗?
g++ -m64 -c -g -I/usr/include/boost -I/usr/include -std=c++11 -MMD -MP -MF build/Debug/GNU-Linux-x86/Idx.o.d -o build/Debug/GNU-Linux-x86/Idx.o Idx.cpp
/usr/include/c++/4.8/ext/new_allocator.h: In instantiation of ‘void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = boost::shared_ptr<Stk>; _Args = {const boost::shared_ptr<Stk>&}; _Tp = boost::shared_ptr<Stk>]’:
/usr/include/c++/4.8/bits/alloc_traits.h:254:4: required from ‘static typename std::enable_if<std::allocator_traits<_Alloc>::__construct_helper<_Tp, _Args>::value, void>::type std::allocator_traits<_Alloc>::_S_construct(_Alloc&, _Tp*, _Args&& ...) [with _Tp = boost::shared_ptr<Stk>; _Args = {const boost::shared_ptr<Stk>&}; _Alloc = std::allocator<boost::shared_ptr<Stk> >; typename std::enable_if<std::allocator_traits<_Alloc>::__construct_helper<_Tp, _Args>::value, void>::type = void]’
/usr/include/c++/4.8/bits/alloc_traits.h:393:57: required from ‘static decltype (_S_construct(__a, __p, (forward<_Args>)(std::allocator_traits::construct::__args)...)) std::allocator_traits<_Alloc>::construct(_Alloc&, _Tp*, _Args&& ...) [with _Tp = boost::shared_ptr<Stk>; _Args = {const boost::shared_ptr<Stk>&}; _Alloc = std::allocator<boost::shared_ptr<Stk> >; decltype (_S_construct(__a, __p, (forward<_Args>)(std::allocator_traits::construct::__args)...)) = <type error>]’
/usr/include/c++/4.8/bits/stl_vector.h:906:34: required from ‘void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = boost::shared_ptr<Stk>; _Alloc = std::allocator<boost::shared_ptr<Stk> >; std::vector<_Tp, _Alloc>::value_type = boost::shared_ptr<Stk>]’
Idx.cpp:22:35: required from here
/usr/include/c++/4.8/ext/new_allocator.h:120:4: error: use of deleted function ‘boost::shared_ptr<Stk>::shared_ptr(const boost::shared_ptr<Stk>&)’
{ ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
^
In file included from /usr/include/boost/shared_ptr.hpp:17:0,
from Idx.h:10,
from Idx.cpp:1:
/usr/include/boost/smart_ptr/shared_ptr.hpp:168:25: note: ‘boost::shared_ptr<Stk>::shared_ptr(const boost::shared_ptr<Stk>&)’ is implicitly declared as deleted because ‘boost::shared_ptr<Stk>’ declares a move constructor or move assignment operator
template<class T> class shared_ptr
^
/usr/include/c++/4.8/bits/stl_construct.h: In instantiation of ‘void std::_Construct(_T1*, _Args&& ...) [with _T1 = boost::shared_ptr<Stk>; _Args = {boost::shared_ptr<Stk>&}]’:
/usr/include/c++/4.8/bits/stl_uninitialized.h:75:53: required from ‘static _ForwardIterator std::__uninitialized_copy<_TrivialValueTypes>::__uninit_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = boost::shared_ptr<Stk>*; _ForwardIterator = boost::shared_ptr<Stk>*; bool _TrivialValueTypes = false]’
/usr/include/c++/4.8/bits/stl_uninitialized.h:117:41: required from ‘_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = boost::shared_ptr<Stk>*; _ForwardIterator = boost::shared_ptr<Stk>*]’
/usr/include/c++/4.8/bits/stl_uninitialized.h:258:63: required from ‘_ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, std::allocator<_Tp>&) [with _InputIterator = boost::shared_ptr<Stk>*; _ForwardIterator = boost::shared_ptr<Stk>*; _Tp = boost::shared_ptr<Stk>]’
/usr/include/c++/4.8/bits/vector.tcc:209:29: required from ‘std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = boost::shared_ptr<Stk>; _Alloc = std::allocator<boost::shared_ptr<Stk> >]’
Idx.cpp:11:23: required from here
/usr/include/c++/4.8/bits/stl_construct.h:75:7: error: use of deleted function ‘boost::shared_ptr<Stk>::shared_ptr(const boost::shared_ptr<Stk>&)’
{ ::new(static_cast<void*>(__p)) _T1(std::forward<_Args>(__args)...); }
^
/usr/include/c++/4.8/bits/stl_construct.h: In instantiation of ‘void std::_Construct(_T1*, _Args&& ...) [with _T1 = boost::shared_ptr<Stk>; _Args = {const boost::shared_ptr<Stk>&}]’:
/usr/include/c++/4.8/bits/stl_uninitialized.h:75:53: required from ‘static _ForwardIterator std::__uninitialized_copy<_TrivialValueTypes>::__uninit_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = __gnu_cxx::__normal_iterator<const boost::shared_ptr<Stk>*, std::vector<boost::shared_ptr<Stk> > >; _ForwardIterator = boost::shared_ptr<Stk>*; bool _TrivialValueTypes = false]’
/usr/include/c++/4.8/bits/stl_uninitialized.h:117:41: required from ‘_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = __gnu_cxx::__normal_iterator<const boost::shared_ptr<Stk>*, std::vector<boost::shared_ptr<Stk> > >; _ForwardIterator = boost::shared_ptr<Stk>*]’
/usr/include/c++/4.8/bits/stl_uninitialized.h:258:63: required from ‘_ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, std::allocator<_Tp>&) [with _InputIterator = __gnu_cxx::__normal_iterator<const boost::shared_ptr<Stk>*, std::vector<boost::shared_ptr<Stk> > >; _ForwardIterator = boost::shared_ptr<Stk>*; _Tp = boost::shared_ptr<Stk>]’
/usr/include/c++/4.8/bits/stl_vector.h:316:32: required from ‘std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&) [with _Tp = boost::shared_ptr<Stk>; _Alloc = std::allocator<boost::shared_ptr<Stk> >]’
Idx.cpp:28:9: required from here
/usr/include/c++/4.8/bits/stl_construct.h:75:7: error: use of deleted function ‘boost::shared_ptr<Stk>::shared_ptr(const boost::shared_ptr<Stk>&)’
/usr/include/boost/smart_ptr/shared_ptr.hpp: In instantiation of ‘boost::shared_ptr<T>& boost::shared_ptr<T>::operator=(const boost::shared_ptr<T>&) [with T = Stk]’:
/usr/include/c++/4.8/bits/stl_algobase.h:335:18: required from ‘static _OI std::__copy_move<false, false, std::random_access_iterator_tag>::__copy_m(_II, _II, _OI) [with _II = const boost::shared_ptr<Stk>*; _OI = boost::shared_ptr<Stk>*]’
/usr/include/c++/4.8/bits/stl_algobase.h:390:70: required from ‘_OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove = false; _II = const boost::shared_ptr<Stk>*; _OI = boost::shared_ptr<Stk>*]’
/usr/include/c++/4.8/bits/stl_algobase.h:428:38: required from ‘_OI std::__copy_move_a2(_II, _II, _OI) [with bool _IsMove = false; _II = __gnu_cxx::__normal_iterator<const boost::shared_ptr<Stk>*, std::vector<boost::shared_ptr<Stk> > >; _OI = __gnu_cxx::__normal_iterator<boost::shared_ptr<Stk>*, std::vector<boost::shared_ptr<Stk> > >]’
/usr/include/c++/4.8/bits/stl_algobase.h:460:17: required from ‘_OI std::copy(_II, _II, _OI) [with _II = __gnu_cxx::__normal_iterator<const boost::shared_ptr<Stk>*, std::vector<boost::shared_ptr<Stk> > >; _OI = __gnu_cxx::__normal_iterator<boost::shared_ptr<Stk>*, std::vector<boost::shared_ptr<Stk> > >]’
/usr/include/c++/4.8/bits/vector.tcc:199:63: required from ‘std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = boost::shared_ptr<Stk>; _Alloc = std::allocator<boost::shared_ptr<Stk> >]’
Idx.cpp:11:23: required from here
/usr/include/boost/smart_ptr/shared_ptr.hpp:305:9: error: use of deleted function ‘boost::shared_ptr<Stk>::shared_ptr(const boost::shared_ptr<Stk>&)’
this_type(r).swap(*this);
这是相关类的头文件(Idx.h):
#ifndef Idx_H
#define Idx_H
#include "Stk.h"
#include <vector>
#include <unordered_map>
#include <string>
#include <boost/shared_ptr.hpp>
using namespace std;
class Idx
{
public:
Idx();
Idx(string sid);
Idx(string sid, vector<boost::shared_ptr<Stk> > Idxinstrslist, unordered_map<string,double> Idxwtings);
~Idx();
vector<boost::shared_ptr<Stk> > getIdxinstrsList();
void addinstrToIdx(boost::shared_ptr<Stk> s, double wting);
void setIdxinstrsList(vector<boost::shared_ptr<Stk> > indinstrlist);
double getIdxStkwting(string sid);
private:
vector<boost::shared_ptr<Stk> > Idxinstrslist;
unordered_map<string,double> Idxwtingsdict;
string sid;
};
#endif
和来源(第 22 行指的是向量 push_back):
#include "Idx.h"
Idx::Idx(){}
Idx::Idx(string id){
sid = id;
}
Idx::Idx(string id,vector<boost::shared_ptr<Stk> > Idxinstrlist, unordered_map<string,double> Idxwtings){
sid = id;
Idxinstrslist = Idxinstrlist;
Idxwtingsdict = Idxwtings;
}
Idx::~Idx(){}
void Idx::addinstrToIdx(boost::shared_ptr<Stk> s, double wting){
string sid = s->getSecurityID();
if(Idxwtingsdict.count(sid)==0)
{
//THINK ITS COMPLAINING ABOUT THIS LINE......................................
Idxinstrslist.push_back(s);
Idxwtingsdict[sid] = wting;
}
}
vector<boost::shared_ptr<Stk> > Idx::getIdxinstrsList(){
return Idxinstrslist;
}
void Idx::setIdxinstrsList(vector<boost::shared_ptr<Stk> > indinstrlist){
Idxinstrslist = indinstrlist;
}
double Idx::getIdxStkwting(string sid){
double wting = 0;
if(Idxwtingsdict.count(sid) == 1){
wting = Idxwtingsdict[sid];
}
else
{
cout << "problem" << endl;
}
return wting;
}