在c++中使用lambdas时出现奇怪的编译器消息
Strange compiler messages when using lambdas in C++
所以我在c++项目中添加了lambdas的使用,现在编译器给出了这样的输出:
9>C:Program Files (x86)Microsoft Visual Studio 10.0VCincludexxcallobj(13): warning C4800: 'BOOL' : forcing value to bool 'true' or 'false' (performance warning)
3> C:Program Files (x86)Microsoft Visual Studio 10.0VCincludexxfunction(386) : see reference to class template instantiation 'std::tr1::_Impl_no_alloc0<_Callable,_Rx>' being compiled
3> with
3> [
3> _Callable=_MyWrapper,
3> _Rx=bool
3> ]
3> C:Program Files (x86)Microsoft Visual Studio 10.0VCincludexxfunction(369) : see reference to function template instantiation 'void std::tr1::_Function_impl0<_Ret>::_Reset0o<_Myimpl,_Fty,std::allocator<_Ty>>(_Fty,_Alloc)' being compiled
3> with
3> [
3> _Ret=bool,
3> _Fty=`anonymous-namespace'::<lambda3>,
3> _Ty=std::tr1::_Function_impl0<bool>,
3> _Alloc=std::allocator<std::tr1::_Function_impl0<bool>>
3> ]
3> C:Program Files (x86)Microsoft Visual Studio 10.0VCincludefunctional(113) : see reference to function template instantiation 'void std::tr1::_Function_impl0<_Ret>::_Reset<_Fx>(_Fty)' being compiled
3> with
3> [
3> _Ret=bool,
3> _Fx=`anonymous-namespace'::<lambda3>,
3> _Fty=`anonymous-namespace'::<lambda3>
3> ]
3> ....CommonIOFile.cpp(1162) : see reference to function template instantiation 'std::tr1::function<_Fty>::function<`anonymous-namespace'::<lambda3>>(_Fx)' being compiled
3> with
3> [
3> _Fty=bool (void),
3> _Fx=`anonymous-namespace'::<lambda3>
3> ]
lambda的代码是:
在。h:
typedef std::function<bool ()> RepeatingFunction;
static bool RepeatFileOperation(RepeatingFunction callback);
static bool Copy(CString file, CString copyFileName, bool failIfExists = true);
在。cpp中:
bool IOFile::RepeatFileOperation(RepeatingFunction callback)
{
const int times_to_retry = 10;
bool succeed = false;
// Retry a few times if it doesn't work
int retries = 0;
do
{
// Perform the caller's action on the file
succeed = callback();
}
while (!succeed && retries++ < times_to_retry);
return succeed;
}
bool IOFile::Copy(CString file, CString copyFileName, bool failIfExists)
{
return RepeatFileOperation([&] {
return CopyFile(file, copyFileName, static_cast<BOOL>(failIfExists));
});
}
程序仍然可以正常编译。我在谷歌上搜索了这个错误,发现人们得到了类似的信息,但在他们的情况下,程序没有构建。在所有情况下,似乎他们的构建错误都是关于前向声明的,但正如我所说的,我的构建很好,我在头文件中包括<functional>
,所以它应该能够找到它。
这些消息是我应该担心的还是他们只是预期的行为?
CopyFile
不返回bool
,但是您隐式地将其结果转换为bool
。只需添加显式强制转换return static_cast<bool>(CopyFile(...
相关文章:
- 在线编译器中的分段C++没有打印消息
- 编译器收到错误消息(textc.exe已停止)
- 无法理解编译器在复制构造函数上引发的错误消息
- C++ 文本消息解码器脚本 编译器 "expects unqualified id" 之前 if 和 else 语句
- 使用constexpr c-string作为编译器错误消息
- 我通过编译器C 11收到了UVA在线法官的错误消息.我永远不知道为什么会产生此错误
- "enable_if"使编译器很难生成可读的错误消息,这是怎么回事
- 当试图检测基类是否具有虚拟破坏者时,如何获取正确的编译器错误消息
- 为什么编译器对auto x=a给出不同的警告消息;和auto x(a)
- 内部编译器错误消息意味着什么,我能做些什么
- 禁用 g++"注意候选者是.." 编译器消息
- 如何使用模板化库控制静态分析编译器错误消息
- gcc编译器错误消息路径取消父级
- C和C++编译器为下面的代码给出了不同的消息,原因是什么
- 带有自定义消息的基于模板的编译时断言只能在某些编译器中编译
- c++项目已成功构建,但给出了g++编译器错误消息
- c++eclipse奇数编译器错误消息
- 在c++中使用lambdas时出现奇怪的编译器消息
- 编译器错误消息错误:令牌之前的预期')' '*'。我的构造函数出错
- 需要帮助C++编译器和链接器错误消息