2016-10-27 4 views
-1

이봐, 난 내 IStream을 과부하 기능이 오류가 계속 모두 다음과 같이C++ 오버로딩 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 >> CB.data"에서 오류가 발생하고 있지만 너비와 높이가 적절합니다.

ColorBlob-> data는 Colors의 동적 2D 배열입니다.

답변

0

정확하게 이해한다면 을 두 개의 인수 istreamColor**에 대해 호출하려고합니다. 그건 좋지 않다. 이 연산자는 istream&ColorBlob&에 대해 istream&Color**에 대해 정의되지 않았습니다.

+0

답변 해 주셔서 감사합니다. 나는이 기능이 어떻게 작동하는지에 대해 꽤 혼란 스럽다. 나는 main에서 "cin >> ColorBlobObject;라는 호출을 받았다." 및 함수 정의 "istream & 연산자 >> (istream & istrm, ColorBlob & CB)"ColorBlobObject의 색상을 변경하기위한 색상 입력을 얻으려고합니다. – kevinHunger

+0

'istream & operator >> (istream & istrm, ColorBlob & CB) 오버로드가 정상적으로 작동합니다. 그런 식으로 보자.'istrm'에서 ** pointer ** ** pointer ** ** 데이터를'Color'로 옮기고 싶습니다. 어떻게하면 컴파일러가 정확히 그 뜻을 알 수 있습니까? 컴파일러'Color **'는 기본적으로'int' (당연히 지나치게 단순화되었지만 지금은 충분해야합니다)이므로 컴파일러는 여러분이 원하는 것을 수행하는 방법을 알 수 없습니다. – Lehu