我对C++的了解很少,因为我只接受了几个类。我不了解使用friend函数重载输入的基本情况,输出流操作符是具有x,y实例变量的Point对象的“简单示例”。现在我在看一个真实的项目,试图了解有人写了和正在错误:重载操作符>>()
error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'const char [2]' (or there is no acceptable conversion)
1> c:\program files\microsoft visual studio 9.0\vc\include\istream(1000): could be 'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,signed char *)' [found using argument-dependent lookup]
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
noob问题(1),有人可以解释什么是basic_istream?错误点:
template<class _Traits> inline
basic_istream<char, _Traits>& __CLRCALL_OR_CDECL operator>>(
basic_istream<char, _Traits>& _Istr, signed char *_Str)
{ // extract a signed char NTBS
return (_Istr >> (char *)_Str);
}
另一部分错误指向是:
void input(std::istream &in = std::cin)
{in >> "(" >> X >> "," >> Y >> "," >> Z >> ")" ; }
inline friend std::istream& operator >> (std::istream& in, Coord &val)
{val.input(in); return in; };
不知道什么是错误的看着我有限的知识。它似乎是抱怨不是inline friend std :: istream & operator >>函数中的正确类型,因为basic_istream模板中存在错误(我不确定那里发生了什么)。任何建议将不胜感激。谢谢!
_Never_ __undersand__使用朋友的基本情况......无论如何。 ':)' – sbi 2010-10-04 20:11:25