我正在使用Visual C++ 2008 SP1 Pro.以下代码片段将无法编译:
int main(void) {
System::Boolean^ foobar = true;
if (foobar == true) {
System::Console::Write("yeah!");
}
}
Run Code Online (Sandbox Code Playgroud)
它给出了以下错误:
1>.\main.cpp(3) : warning C4805: '==' : unsafe mix of type 'System::Boolean ^' and type 'bool' in operation
1>.\main.cpp(3) : error C2446: '==' : no conversion from 'int' to 'System::Boolean ^'
1> No user-defined-conversion operator available, or
1> No standard conversion exists from the boxed form of the arithmetic type to the target type
1>.\main.cpp(3) : error C2040: '==' : 'System::Boolean ^' differs in levels of indirection from 'int'
Run Code Online (Sandbox Code Playgroud)
以下代码编译正常:
int main(void) {
System::Boolean^ foobar = true;
if (foobar->Equals(true)) {
System::Console::Write("yeah!");
}
}
Run Code Online (Sandbox Code Playgroud)
难道我做错了什么?有没有更好的方法在C++/CLI中比较System :: Boolean和bool而不是使用 - > Equals()和 - > CompareTo()?
| 归档时间: |
|
| 查看次数: |
7343 次 |
| 最近记录: |