Sure, Classes is hard (and still learning), Pointers are tricky (Not very good at it yet), but the weirdest of them all is Operator Overloading. I''ve read the GT Operator Overloading tut, but I just can''t seem to get it.
Now, for the sake of GDN bandwith, I "tried" to make a simple Operator Overloading program.
#include <iostream>
using namespace std;
class ELBEN
{
public:
ELBEN():age(13) { } //Nothing done
ELBEN(int ageElben):age(ageElben) { } //Same same...
ELBEN& operator +(const ELBEN&);
int age;
};
ELBEN ELBEN::operator +(const ELBEN &temp)
{
ELBEN result(age + temp.age);
return result;
}
int main()
{
ELBEN elben1(13);
ELBEN elben2(14);
ELBEN elbenFinal = elben1 + elben2;
cout << elbenFinal.age;
return 0;
}
Of coarse, errors appeared. 4, to be exact.
- c:\Documents and Settings\COMP\My Documents\Visual Studio Projects\Operator Overloading 2\main.cpp(15): error C2556: ''ELBEN ELBEN::operator +(const ELBEN &)'' : overloaded function differs only by return type from ''ELBEN &ELBEN::operator +(const ELBEN &)''
- c:\Documents and Settings\COMP\My Documents\Visual Studio Projects\Operator Overloading 2\main.cpp(15): error C2040: ''ELBEN::operator`+'''' : ''ELBEN (const ELBEN &)'' differs in levels of indirection from ''ELBEN &(const ELBEN &)''
-
c:\Documents and Settings\COMP\My Documents\Visual Studio Projects\Operator Overloading 2\main.cpp(24): error C2264: ''ELBEN::operator`+'''' : error in function definition or declaration; function not called
-
c:\Documents and Settings\COMP\My Documents\Visual Studio Projects\Operator Overloading 2\main.cpp(24): error C2088: ''+'' : illegal for class
Don''t critize me of the bad coding (ie no .h file, no class decleration file), I''m just trying to be simple.
Actually, this program is very poorly coded, very very poorly coded.
So if someone is kind enough, would you kindly make a simple program using ONLY one or two operator overloads (The smaller the better)? Thank you.
Visit my game programming website at
www.wiseelben.com
E-mail:
wiseelben@wiseelben.com
AIM:
WiseElben
ICQ: 299127026