1

この行でコンパイルエラーが発生します:

cout << (MenuItems[i].Checkbox ? (MenuItems[i].Value ? txt::mn_yes : txt::mn_no) : MenuItems[i].Value)

エラー:

menu.cpp|68|error: invalid conversion from 'int' to 'const char*'
menu.cpp|68|error:   initializing argument 1 of 'std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]'

MenuItemsは、次のクラスのstd::vectorです。

class CMenuItem
{
public:
string Name;
int Value;
int MinValue, MaxValue;
bool Checkbox;
CMenuItem (string, int, int, int);
CMenuItem (string, bool);
};

mn_yesとmn_noはstd::stringsです。

コンパイラはMinGW(code ::blocksで配布されるバージョン)です。

4

1 に答える 1

6

可能な2つの条件値は、共通の型に変換可能である必要があります。問題は、外側の条件の左側が次のことです。

(MenuItems[i].Value ? txt::mn_yes : txt::mn_no)

は常にですstringが、正しいです:

MenuItems[i].Value

intです。const char *->に移動して方法を見つけようとしますが、変換stringはできません(意味がないため、これは良いことです)。ただ行う:intconst char *

if(MenuItems[i].Checkbox)
{
    cout << (MenuItems[i].Value ? txt::mn_yes : txt::mn_no);
}
else
{
    cout << MenuItems[i].Value;
}

または類似。

于 2010-09-18T21:47:09.780 に答える