000
16.03.2004, 18:49 Uhr
Pablo
Supertux (Operator)
|
Ich habe das jetzt nur aus Übung gemacht
C++: |
// cl.h #ifndef CAT_H #define CAT_H
#include <iostream> class Cat { int val; public: Cat(); Cat(int x); void setval(int x); int getval(); std::ostream& operator<<(std::ostream& out, const Cat& v); }; #endif
|
C++: |
//cl.cpp #include "cl.h" Cat::Cat() { this->val = 0; }
Cat::Cat(int x) { this->val = x; }
void Cat::setval(int x) { this->val = x; }
int Cat::getval() { return this->val; }
std::ostream& operator<<(std::ostream& out, const Cat& v) { out << v.getval(); return out; }
int main() { Cat a,b(1); a.setval(19); std::cout << "a.getval()=" << a.getval() << std::endl << "b.getval()=" << b.getval() << std::endl; return 0; }
|
Wieso kriege ich folgenden Fehler? (g++ (GCC) 3.2.3 20030422 )
bash: |
rex@supertux:~/programmierung/c++/kkk> g++ cl.cpp -o cl In file included from cl.cpp:1: cl.h:13: `std::ostream& Cat::operator<<(std::ostream&, const Cat&)' must take exactly one argument cl.cpp: In function `std::ostream& operator<<(std::ostream&, const Cat&)': cl.cpp:24: passing `const Cat' as `this' argument of `int Cat::getval()' discards qualifiers
|
Was habe ich falsch gemacht? -- A! Elbereth Gilthoniel! silivren penna míriel o menel aglar elenath, Gilthoniel, A! Elbereth! Dieser Post wurde am 16.03.2004 um 18:49 Uhr von Pablo editiert. |