[C++] error: 'main()::Liczba main()::Liczba::operator+(const main()::Liczba&, const main()::Liczba&)' must take either zero or one argument|
Ostatnio zmodyfikowano 2014-12-23 18:08
killermannnnn Temat założony przez niniejszego użytkownika |
[C++] error: 'main()::Liczba main()::Liczba::operator+(const main()::Liczba&, const main()::Liczba&)' must take either zero or one argument| » 2014-12-23 17:03:45 Co jest źle w tym kodzie? Dostaje takie błędy: |14|error: 'main()::Liczba main()::Liczba::operator+(const main()::Liczba&, const main()::Liczba&)' must take either zero or one argument| |23|error: no match for 'operator+' in 'jeden + dwa'| #include <iostream>
using namespace std;
int main() { struct Liczba { int rzeczyw; int zespol; Liczba( int a, int b ) : rzeczyw( a ) , zespol( b ) { }; Liczba operator +( const Liczba & a, const Liczba & b ) { return Liczba( a.rzeczyw + b.rzeczyw, a.zespol + b.zespol ); } }; Liczba jeden( 2, 5 ), dwa( 1, 3 ); Liczba trzy = jeden + dwa; cout << trzy.rzeczyw << " " << trzy.zespol << endl; }
|
|
szymeczek31 |
» 2014-12-23 17:50:37 EDIT: To powinno rozwiązać problem #include <iostream> using namespace std;
class Liczba { int liczba1; int liczba2; public: int rzeczyw; int zespol; Liczba( int a, int b ) : rzeczyw( a ) , zespol( b ) { liczba1 = a; liczba2 = b; } Liczba operator +( const Liczba & a ) { return Liczba( a.rzeczyw + liczba1, a.zespol + liczba2 ); } };
int main() { Liczba jeden( 2, 5 ), dwa( 1, 3 ); Liczba trzy = jeden + dwa; cout << trzy.rzeczyw << " " << trzy.zespol << endl; } |
|
killermannnnn Temat założony przez niniejszego użytkownika |
» 2014-12-23 18:08:11 OK, dzięki za odpowiedź |
|
« 1 » |