Allright, as most of you might know, you can define an operator to work with a Data type within a definition. This means using something like this:
| CODE |
fraction operator+(const fraction & f1, const fraction & f2);
|
Now this is great in most programs, you pass the operator function by falue, and when the operator is called, it works great. But in Devc++, there is a problem. If you, say..
| CODE |
fraction myfraction1; //give them values, doesnt matter what. fraction myfraction2;
cout << myfraction1+myfraction2;
|
Then in Devc++, after compiled, and you run, you are going to get an error. Now, this code will work perfect in most C++ programming environments. But in Devc++, there seems to be a problem. I'm not exactly sure why, and if anyone could help explain why this happens, I'll be greatful for the knowledge.
There is only one solution...You must pass the operator function by reference... This is bad programming practice, and in fact, you will get a warning, telling you that you are passing the operator by reference.
It will look something like this:
| CODE |
fraction & operator+(const fraction & f1, const fraction & f2);
|
This presents yet another problem, though. If you use coding like what is below, the << operator will erase what is in f1 because of memory stack, and you will get some wierd numbers out of the operation.
Instead you must define an Extra Variable.
| CODE |
fraction f3;
f3 = (F1 + F2); cout << f3;
|
I hope this helps someone. I've been trying to debug a program with this problem for 3 days. Finally I gave out and asked my instructor. All this is the result and my understanding of what he told me from memory. If anything you see is wrong, let me know, because this is how I understood the problem with Devc++.