嘿,我在istream重载函数中一直收到此错误:
ColorBlob.cpp: In function 'std::istream& operator>>(std::istream&, ColorBlob&)':
ColorBlob.cpp:204:17: error: cannot bind 'std::istream {aka std::basic_istream<char>}' lvalue to 'std::basic_istream<char>&&'
In file included from c:\program files (x86)\codeblocks\mingw\bin\../lib/gcc/min
gw32/4.7.1/include/c++/iostream:41:0,
from Color.h:14,
from ColorBlob.h:13,
from ColorBlob.cpp:11:
c:\program files (x86)\codeblocks\mingw\bin\../lib/gcc/mingw32/4.7.1/include/c++
/istream:866:5: error: initializing argument 1 of 'std::basic_istream<_CharT,
_Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&&, _Tp&) [with _Ch
arT = char; _Traits = std::char_traits<char>; _Tp = Color**]'"
我的功能定义如下:
istream& operator>>(istream& istrm, ColorBlob& CB){
double red,blue,green;
cout << "Enter red value";
cin >> red;
cout << "Enter green value";
cin >> green;
cout << "Enter blue value";
cin >> blue;
CB.setColor(Color(red, green, blue));
istrm >> CB.width;
istrm >> CB.height;
istrm >> CB.data;
return istrm;
}
错误发生在“istrm&gt;&gt; CB.data”上,但它的宽度和高度都很好。
ColorBlob-&gt;数据是Color的动态2D数组。
答案 0 :(得分:0)
如果我理解正确,您正尝试在istream& operator>>(istream& istrm, ColorBlob& CB)
和istream
两个参数上致电Color**
。这是不好的。您为istream&
和ColorBlob&
定义了此运算符,而不是istream&
和Color**
。