-1

Hey all I keep getting this error in my istream overload function:

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**]'"

My function is defined as follows:

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;
}

The error is happening on "istrm >> CB.data", but it is taking the width and height fine.

ColorBlob->data is a dynamic 2D array of Colors.

1 Answers1

0

If I understand you correctly you are trying to call istream& operator>>(istream& istrm, ColorBlob& CB) on two arguments istream and Color** . That is not good. You have this operator defined for istream& and ColorBlob& not for istream& and Color**.

Lehu
  • 761
  • 4
  • 14
  • Thanks for answering. I guess I am pretty confused on how this function is even supposed to work. I am given the call in main with "cin >> ColorBlobObject;" and the function definition "istream& operator>>(istream& istrm, ColorBlob& CB)" and am supposed to get color input to change the colors of the ColorBlobObject. – kevinHunger Oct 27 '16 at 22:11
  • Overload `istream& operator>>(istream& istrm, ColorBlob& CB)` works fine. But look at it that way: you want to transfer some data from `istrm` to **pointer** to **pointer** to `Color`. How could compiler know what exactly you mean by that? For compiler `Color**` is basically an `int` (it's of course oversimplification but it have to suffice for now) so compiler have no way of knowing how to perform what you wish of it. – Lehu Oct 27 '16 at 22:16