type_traits(1545): error C2280:

2019-08-23 21:08发布

问题:

vs2013,it's wrongs:

D:\vs2013\VC\include\type_traits(1545): error C2280: “std::basic_stringstream<char,std::char_traits<char>,std::allocator<char>>::basic_stringstream(const std::basic_stringstream<char,std::char_traits<char>,std::allocator<char>> &)”: 尝试引用已删除的函数
        1>          D:\vs2013\VC\include\sstream(631) : 参见“std::basic_stringstream<char,std::char_traits<char>,std::allocator<char>>::basic_stringstream”的声明
        1>          D:\vs2013\VC\include\thread(47): 参见对正在编译的函数 模板 实例化“std::basic_stringstream<char,std::char_traits<char>,std::allocator<char>> std::_Decay_copy<std::stringstream&>(_Ty)”的引用
        1>          with
        1>          [
        1>              _Ty=std::stringstream &
        1>          ]
        1>          GA_SpikeDlg.cpp(253): 参见对正在编译的函数 模板 实例化“std::thread::thread<float(__cdecl &)(M_args,double,double,double,double,int [],M_args_Bound [],int,float,float,int,float,float,std::stringstream &),M_args&,double&,double&,double&,double&,int(&)[5],M_args_Bound(&)[5],int&,float&,float&,const int&,float&,float&,std::stringstream&>(_Fn,M_args &,double &,double &,double &,double &,int (&)[5],M_args_Bound (&)[5],int &,float &,float &,const int &,float &,float &,std::stringstream &)”的引用
        1>          with
        1>          [
        1>              _Fn=float (__cdecl &)(M_args,double,double,double,double,int [],M_args_Bound [],int,float,float,int,float,float,std::stringstream &)
        1>          ]
        1>  GA_Spike.cpp
        1>  cuda_transfer.cpp
        1>  正在生成代码...
        ========== 全部重新生成:  成功 0 个,失败 1 个,跳过 0 个 ==========

my main code is:

thread t1(task1, Parameter_, Mtime, tempVB, TimeStep, m_I, FlagParameter, Parameter_Bound, MaxGeneration, gL, C, POPULATION_SIZE, crossver, mutations, strResult);

void task1(M_args Parameter_, double Mtime, double tempVB, double TimeStep, double m_I, int FlagParameter[], M_args_Bound Parameter_Bound[], int MaxGeneration, float gL, float C, const int POPULATION_SIZE, float crossver, float mutations, stringstream &strResult)
{
solveGPU_cpp(Parameter_, Mtime, tempVB, TimeStep, m_I, FlagParameter, Parameter_Bound, MaxGeneration, gL, C, POPULATION_SIZE, crossver, mutations, strResult);
    cout << "task1 says: " << endl;
}

AND solveGPU_cpp is a Interface functions of .cu so what's wrong?

回答1:

The last parameter is by reference you need std::ref(strResult).

Like:

thread t1(task1, Parameter_, Mtime, tempVB, TimeStep, m_I, FlagParameter, Parameter_Bound, MaxGeneration, gL, C, POPULATION_SIZE, crossver, mutations,
  std::ref(strResult));    // Pass reference

Here a quick & dirty playground - https://godbolt.org/g/iQzJPH