显式运算符bool错误 [英] explicit operator bool error
本文介绍了显式运算符bool错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我得到显式运算符bool $ c $时,k(C2071)%3bk(VS.ErrorList)& rd = truerel =nofollow>编译器错误C2071 c>:
I get the Compiler Error C2071 when I try to implement the explicit operator bool
:
class C
{
public:
explicit operator bool() const
{
return !!*this;
}
};
为什么?我如何解决这个问题?
我使用Visual Studio 2012 RC。
Why? How can I solve this problem?
I'm using Visual Studio 2012 RC.
推荐答案
Visual Studio 2012不支持显式转换运算符,请参见 Visual C ++ 11中的C ++ 11功能。
Visual Studio 2012 does not support explicit conversion operators, see C++11 Features in Visual C++ 11.
这些文章介绍了安全bool惯用语:
- http://www.artima.com/cppsource/safebool.html
- http://en.wikibooks.org/wiki/More_C++ _Idioms / Safe_bool
- http://www.artima.com/cppsource/safebool.html
- http://en.wikibooks.org/wiki/More_C++_Idioms/Safe_bool
这篇关于显式运算符bool错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文