为什么使用std::bind出现参数错误
why occurred parameter error using std::bind
我正在研究c++11规范
使用std::bind,我不明白为什么会出现错误
下面是简单的代码
class ClassInfo
{
public:
ClassInfo() : nID(0) {}
~ClassInfo() {}
bool GetInfo1(int nVal1, int& nOutVal1, std::string& strOut1, std::string& strOut2 )
{
nOutVal1 = nID;
strOut1 = "out1";
strOut2 = "out2";
return true;
}
bool GetInfo2(int nVal1, int& nOutVal1, std::string& strOut1, std::string& strOut2, std::string& strOut3 )
{
nOutVal1 = nID;
strOut1 = "out1";
strOut2 = "out2";
strOut3 = "out3";
return true;
}
int nID;
};
int main()
{
std::shared_ptr<ClassInfo> spInfo = std::make_shared<ClassInfo>();
spInfo->nID = 10;
int nVal1 = 5;
int nOutVal1;
std::string strOut1;
std::string strOut2;
std::string strOut3;
auto _func1 = std::bind(&ClassInfo::GetInfo1, spInfo, nVal1, std::ref(nOutVal1), std::ref(strOut1), std::ref(strOut2));
_func1();
auto _func2 = std::bind(&ClassInfo::GetInfo2, spInfo, nVal1, std::ref(nOutVal1), std::ref(strOut1), std::ref(strOut2), std::ref(strOut3));
_func2();
}
此代码未编译。。
auto _func1 = std::bind(&ClassInfo::GetInfo1, spInfo, nVal1, std::ref(nOutVal1), std::ref(strOut1), std::ref(strOut2));
这还可以,但是
auto _func2 = std::bind(&ClassInfo::GetInfo2, spInfo, nVal1, std::ref(nOutVal1), std::ref(strOut1), std::ref(strOut2), std::ref(strOut3));
此代码中发生编译错误。为什么会出现错误?
我解决了这个问题。此错误发生在visualstudio2012。视觉工作室2015是明确的。所以我解决了使用增强绑定
相关文章:
- C++声明模板参数阴影模板参数错误
- 为什么 CRTP 模板C++给出无效参数错误?
- (C/C++)fscanf_s从txt文件以字符形式读取数组时缺少整数参数错误
- 参数错误可能与类型不匹配有关?
- printf 和 strftime 的参数错误无效
- 如何修复"ctypes"。参数错误:参数 2:<键入"异常.类型错误">:RaspberryPi 中的错误类型"错误
- 如何修复"没有重载函数需要 2 个参数"错误C++
- 术语不计算为函数采用 1 个参数错误?
- 从带有 getline() 的文件读入一行上有多个信息得到无效参数错误
- 为什么我不能像使用 std::string::size_type 那样使用 QList::size_type?(模板参数错误)
- cudaFreeHost() 无效参数错误
- 精神语法不会编译:函数模板参数错误?
- C 功能具有参考参数错误的迭代器错误.寻求解释
- 使用getDefaultCommConfig使用无效的参数错误
- C++ 可变参数模板和模板模板参数:错误:模板参数列表中参数 1 处的类型/值不匹配
- 使用SWIG生成的Python库时,向量分配器参数错误
- 错误C2664:无法转换参数错误
- C 作为参数错误的功能
- 命令行参数错误
- 增强Python参数错误