enum Sex{MALE=0, FEMALE=1};
void f()
{
Sex s;
s = FEMALE;
cout << s == FEMALE ? "OK" : "Error" << endl; // line 64
}
以上代码编译报错:
--------------------Configuration: Logic - Win32 Debug--------------------
Compiling...
main.cpp
I:\MYPROJECTS_OLD\EX\Logic\main.cpp(64) : error C2679: binary '==' : no operator defined which takes a right-hand operand of type 'enum Sex' (or there is no acceptable conversion)
I:\MYPROJECTS_OLD\EX\Logic\main.cpp(64) : error C2563: mismatch in formal parameter list
I:\MYPROJECTS_OLD\EX\Logic\main.cpp(64) : error C2568: '<<' : unable to resolve function overload
could be 'class std::basic_ostream<unsigned short,struct std::char_traits<unsigned short> > &__cdecl std::endl(class std::basic_ostream<unsigned short,struct std::char_traits<unsigned short> > &)'
i:\program files\microsoft visual studio\vc98\include\ostream(377) : see declaration of 'endl'
or 'class std::basic_ostream<char,struct std::char_traits<char> > &__cdecl std::endl(class std::basic_ostream<char,struct std::char_traits<char> > &)'
i:\program files\microsoft visual studio\vc98\include\ostream(372) : see declaration of 'endl'
or 'class std::basic_ostream<_E,_Tr> &__cdecl std::endl(class std::basic_ostream<_E,_Tr> &)'
i:\program files\microsoft visual studio\vc98\include\ostream(367) : see declaration of 'endl'
Error executing cl.exe.main.obj - 3 error(s), 0 warning(s)
找了半天也不知道原因。请高手指教!
void f()
{
Sex s;
s = FEMALE;
cout << s == FEMALE ? "OK" : "Error" << endl; // line 64
}
以上代码编译报错:
--------------------Configuration: Logic - Win32 Debug--------------------
Compiling...
main.cpp
I:\MYPROJECTS_OLD\EX\Logic\main.cpp(64) : error C2679: binary '==' : no operator defined which takes a right-hand operand of type 'enum Sex' (or there is no acceptable conversion)
I:\MYPROJECTS_OLD\EX\Logic\main.cpp(64) : error C2563: mismatch in formal parameter list
I:\MYPROJECTS_OLD\EX\Logic\main.cpp(64) : error C2568: '<<' : unable to resolve function overload
could be 'class std::basic_ostream<unsigned short,struct std::char_traits<unsigned short> > &__cdecl std::endl(class std::basic_ostream<unsigned short,struct std::char_traits<unsigned short> > &)'
i:\program files\microsoft visual studio\vc98\include\ostream(377) : see declaration of 'endl'
or 'class std::basic_ostream<char,struct std::char_traits<char> > &__cdecl std::endl(class std::basic_ostream<char,struct std::char_traits<char> > &)'
i:\program files\microsoft visual studio\vc98\include\ostream(372) : see declaration of 'endl'
or 'class std::basic_ostream<_E,_Tr> &__cdecl std::endl(class std::basic_ostream<_E,_Tr> &)'
i:\program files\microsoft visual studio\vc98\include\ostream(367) : see declaration of 'endl'
Error executing cl.exe.main.obj - 3 error(s), 0 warning(s)
找了半天也不知道原因。请高手指教!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货