On Suday the 11th of February, 2007 -after 3 and a half years on InvisionFree, we have moved! This old board remains as a read only archive of years past, and registration has been disabled here. All new and current members should register at http://www.cpplc.net/forum .

zIFBoards - Free Forum Hosting
Enjoy forums? Start your own community for free.

Learn More · Register for Free
Welcome to C++ Learning Community. We hope you enjoy your visit.

You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.

Join our community!

If you're already a member please log in to your account to access all of our features:

Name:   Password:

Please help out

  Reply to this topicStart new topicStart Poll

> Quick Tip to all you Devc++ Users, Relational Operators Problems
Posted: Feb 8 2007, 08:06 PM
Quote Post


Group: Members
Posts: 5
Member No.: 2,428
Joined: 31-January 07

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:


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..


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:


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.


cout << (F1 + F2);

Instead you must define an Extra Variable.


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++.

PMEmail Poster
« Next Oldest | C++ Tips | Next Newest »
DealsFor.me - The best sales, coupons, and discounts for you

Topic Options Reply to this topicStart new topicStart Poll

Skin selector developed by XJONX. Skins created by various members of the IF Skin Zone and InvisionFree Skinning

Please help out
Hosted for free by zIFBoards* (Terms of Use: Updated 2/10/2010) | Powered by Invision Power Board v1.3 Final © 2003 IPS, Inc.
Page creation time: 0.0417 seconds · Archive