zagniezdzone operatory
Ostatnio zmodyfikowano 2013-11-13 08:01
hexperos Temat założony przez niniejszego użytkownika |
zagniezdzone operatory » 2013-11-12 20:30:07 czesc. to moj pierwszy post. niedawno wziolem sie za powtorke w c++. postanowilem tak konkretnie sie nim zajac i juz mam dziwny problem. nie logiczny. otoz kod wyglada tak : #include <cstdlib> #include <iostream> #include <string>
using namespace std;
class A { friend ostream & operator <<( ostream & out, A & a ) { out << a.x; return out; } friend istream & operator >>( istream & in, A & a ) { in >> a.x; return in; } public: A() : x( 0 ) { cout << "Konstr. domyslny." << endl; }; A( int x ) { cout << "Konstr. X." << endl; this->x = x; } int getX() const { return x; } void setX( int x ) { this->x = x; } A operator +( const A & a ) const { return A( x + a.x ); } private: int x; };
int main( int argc, char * argv[] ) { A aa0( 25 ); A aa1( 50 ); cout <<( aa0 + aa1 ) << endl; A aa2 = aa0 + aa1; cout << aa2 << endl; system( "PAUSE" ); return EXIT_SUCCESS; }
generalnie to jest jakas klasa A. Tworzone sa 2 obiekty z przeciazonymi operatorami << oraz +. Wszystko jest chyba ok tylko ze zapis w rodzaju cout<<(obj0+obj1)<<endl, nie dziala i krzaczy czyms takim ... 80 D:\Temp4\2013\strumienie\main.cpp no match for 'operator<<' in 'std::operator<< [with _Traits = std::char_traits<char>](((std::basic_ostream<char, std::char_traits<char> >&)(+operator<<(((std::ostream&)(&std::cout)), ((A&)(&aa2))))), ((const char*)" ")) << (&aa0)->A::operator+(((const A&)((const A*)(&aa1))))' bardzo prosil bym o jakies sugestie i pomoc. dzieki. pozdrowienia dla wszystkich. |
|
Monika90 |
» 2013-11-13 08:01:28 Wyrażenie aa0 + aa1 jest R-wartością, a parametrem twojego operatora << jest referencja do nie-const, która wymaga L-wartości. |
|
« 1 » |