Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming

Reply
 
LinkBack Thread Tools
Old 10-12-09   #1 (permalink)
4.0 GHz
 
stn0092's Avatar
 
intel nvidia

Join Date: Jun 2008
Location: N. California
Posts: 603

Rep: 41 stn0092 is acknowledged by some
Unique Rep: 36
Trader Rating: 15
Default Operator Overloading (I think...?)

My assignment is to use the provided private data and member functions and implement them and then test them in some main. Honestly, my understanding of using classes isn't all that great anyway. I was lost form the very start.

Code:
//Rational.h

#ifndef RATIONAL_H_DEF
#define RATIONAL_H_DEF

#include <iostream>
using namespace std;

class Rational
{
	long _p;
	long _q;

	public:

		Rational ( ); //default constructor 
		Rational ( long, long = 1 ); //constructor
		Rational ( const Rational& ); //copy constructor
		Rational& operator= ( const Rational& );
		Rational& operator+= ( const Rational& );
		Rational& operator-= ( const Rational& );
		Rational& operator*= ( const Rational& );
		Rational& operator/= ( const Rational& );
};
#endif
Code:
//Rational.cpp

#include <iostream>
#include "Rational.h"

Rational::Rational ()
{
     _p = 1;
     _q = 1;
}

Rational& operator+= (const Rational& R)
{
     _p = (_p * R._q) + (R._p * _q);
     _q *= R._q;

    //pasted from a previous assignment; not quite sure it works
}
When I try to compile this (g++ pendantic), I get an error about operator+= requiring exactly two arguments.
__________________

System: Lancelot - 2008
CPU
Intel Q9550 E0 @ 4.03GHz (475x8.5)
Motherboard
eVGA 790i FTW SLI
Memory
2x2GB Corsair XMS3 DDR3
Graphics Card
2x eVGA Geforce GTX 285 in SLI
Hard Drive
128GB Falcon SSD, 2x1TB Caviar Black
Sound Card
ASUS Xonar D2
Power Supply
Corsair HX1000W
Case
Lian-Li A70B
CPU cooling
HDT-S1283; Ultra Kaze 3000 @ 2200RPM; Tuniq TX-2
GPU cooling
Stock fan
OS
Windows 7 Professional x64
Monitor
24" Samsung 2493HM
stn0092 is offline   Reply With Quote
Old 10-12-09   #2 (permalink)
4.0 GHz
 
dharmaBum's Avatar
 
intel nvidia

Join Date: Apr 2007
Location: Raleigh, NC
Posts: 747

Rep: 121 dharmaBum is acknowledged by manydharmaBum is acknowledged by many
Unique Rep: 89
Trader Rating: 0
Default

You have:
Quote:
Rational& operator+= (const Rational& R)
Should be:
Quote:
Rational& Rational:: operator+=(const Rational& R)
Also, you need to return something. Because you want the same "Rational" object back:

Quote:
return *this;
"this" is a keyword to the C++ compiler uses to refer to the current object. So, using the statement

Quote:
x+=y;
"this" will refer to x.

The "*" in the return statement is a consequence of "this" actually being a pointer, which for this discussion we need not jump into those dark waters.

This setup with operators allows you to chain them together, like so:

Quote:
x+=y+=z+=a;
Which might seem unwieldy and confusing, but consider another operator chain:

Quote:
cout<<"Hello"<<endl<<"World"<<sizeof(a)<<"and then some!"<<endl;
"<<" here is actually an operator that returns the "stream" (where you write/read things to/from) back, so you can keep using the "<<" operator to mean "output". Similar for cin and ">>".

The equivalent, non-operator, non-object statement would be:

Quote:
printf("Hello\nWorld%dand then some!\n",sizeof(a));
Which is a pain to read and write (especially when all the special codes for numbers and formatting need to be recalled).

Edit: for clarity
__________________
3DMark06: 19091 - 3DMark Vantage: P15264 - SuperPi: 10.968s

Programming Quote of the Day:
Bjarne Stroustrup:
Quote:
There are only two industries that refer to their customers as ‘users’.

System: Europa
CPU
E8500 4.36ghz @ 1.36v
Motherboard
EVGA 780i SLi P05 Bios
Memory
G.SKILL 4GB(2x2GB) @ 924MHz (5-4-4-12-2T)
Graphics Card
2xEVGA 8800GTS (G92) 512MB @800/2000/2110
Hard Drive
Seagate 500gbx2, (fake-)RAID0
Sound Card
Sound Blaster X-Fi XtremeGamer
Power Supply
CORSAIR 1000HX 1000W
Case
Gigabyte GZ-FA2CA-AJB Black Aluminum
CPU cooling
TDX 775 Block, 360 BlackIce rad
GPU cooling
MAZE5x2, TT copper HS
OS
Fedora10-86_64/Vista64
Monitor
22" Samsung SyncMaster 2232BW

Last edited by dharmaBum : 10-12-09 at 08:54 PM
dharmaBum is offline   Reply With Quote
Old 10-12-09   #3 (permalink)
4.0 GHz
 
stn0092's Avatar
 
intel nvidia

Join Date: Jun 2008
Location: N. California
Posts: 603

Rep: 41 stn0092 is acknowledged by some
Unique Rep: 36
Trader Rating: 15
Default

Thanks.

My assignment has me implementing the member functions in a separate .cpp, but, out of curiosity, can I do it right where I define my class?

Code:
//Rational.h

#ifndef RATIONAL_H_DEF
#define RATIONAL_H_DEF

#include <iostream>
using namespace std;

class Rational
{
	long _p;
	long _q;

	public:

		Rational ( ); //default constructor 
		Rational ( long, long = 1 ); //constructor
		Rational ( const Rational& ); //copy constructor
		Rational& operator= ( const Rational& );
		Rational& operator+= ( const Rational& );
		const{
			_p = (_p * R._q) + (R._p * _q);
			_q *= R._q;
			return *this;
		}
		Rational& operator-= ( const Rational& );
		Rational& operator*= ( const Rational& );
		Rational& operator/= ( const Rational& );
		friend ostream& operator<< ( ostream&, const Rational&);
		friend istream& operator>> ( istream&, Rational&);
};
#endif
I won't be doing it that way, but I'm just wondering.
__________________

System: Lancelot - 2008
CPU
Intel Q9550 E0 @ 4.03GHz (475x8.5)
Motherboard
eVGA 790i FTW SLI
Memory
2x2GB Corsair XMS3 DDR3
Graphics Card
2x eVGA Geforce GTX 285 in SLI
Hard Drive
128GB Falcon SSD, 2x1TB Caviar Black
Sound Card
ASUS Xonar D2
Power Supply
Corsair HX1000W
Case
Lian-Li A70B
CPU cooling
HDT-S1283; Ultra Kaze 3000 @ 2200RPM; Tuniq TX-2
GPU cooling
Stock fan
OS
Windows 7 Professional x64
Monitor
24" Samsung 2493HM

Last edited by stn0092 : 10-13-09 at 03:06 AM
stn0092 is offline   Reply With Quote
Old 10-13-09   #4 (permalink)
4.0 GHz
 
dharmaBum's Avatar
 
intel nvidia

Join Date: Apr 2007
Location: Raleigh, NC
Posts: 747

Rep: 121 dharmaBum is acknowledged by manydharmaBum is acknowledged by many
Unique Rep: 89
Trader Rating: 0
Default

Quote:
Originally Posted by stn0092 View Post
Thanks.

My assignment has me implementing the member functions in a separate .cpp, but, out of curiosity, can I do it right where I define my class?

I won't be doing it that way, but I'm just wondering.
Yes, that is fine, but your syntax will throw compile errors here.

You have:

Code:
		Rational& operator+= ( const Rational& );
		const{
			_p = (_p * R._q) + (R._p * _q);
			_q *= R._q;
			return *this;
		}
which is wrong.

Instead, what you can do is simply use the normal syntax of function definitions:

Code:
class Rational{
...
public:
...
		Rational& operator+= ( const Rational& ){
			_p = (_p * R._q) + (R._p * _q);
			_q *= R._q;
			return *this;
		}
...
};
Best coding practice would be to put them in separate files (or, at least, declare before you define). But this is for the sake of the programmer; the compiler doesn't really care.
__________________
3DMark06: 19091 - 3DMark Vantage: P15264 - SuperPi: 10.968s

Programming Quote of the Day:
Bjarne Stroustrup:
Quote:
There are only two industries that refer to their customers as ‘users’.

System: Europa
CPU
E8500 4.36ghz @ 1.36v
Motherboard
EVGA 780i SLi P05 Bios
Memory
G.SKILL 4GB(2x2GB) @ 924MHz (5-4-4-12-2T)
Graphics Card
2xEVGA 8800GTS (G92) 512MB @800/2000/2110
Hard Drive
Seagate 500gbx2, (fake-)RAID0
Sound Card
Sound Blaster X-Fi XtremeGamer
Power Supply
CORSAIR 1000HX 1000W
Case
Gigabyte GZ-FA2CA-AJB Black Aluminum
CPU cooling
TDX 775 Block, 360 BlackIce rad
GPU cooling
MAZE5x2, TT copper HS
OS
Fedora10-86_64/Vista64
Monitor
22" Samsung SyncMaster 2232BW
dharmaBum is offline   Reply With Quote
Old 10-14-09   #5 (permalink)
4.0 GHz
 
stn0092's Avatar
 
intel nvidia

Join Date: Jun 2008
Location: N. California
Posts: 603

Rep: 41 stn0092 is acknowledged by some
Unique Rep: 36
Trader Rating: 15
Default

I need some more help.

I'm trying to implement operator+ using operator+=.

Code:
//Rational.h

#ifndef RATIONAL_H_DEF
#define RATIONAL_H_DEF

#include <iostream>
using namespace std;

class Rational
{
	long _p;
	long _q;

	public:

		Rational ( ); //default constructor 
		Rational ( long, long = 1 ); //constructor
		Rational ( const Rational& ); //copy constructor
		Rational& operator= ( const Rational& );
		Rational& operator+= ( const Rational& );
		friend ostream& operator<< ( ostream&, const Rational&);
		friend istream& operator>> ( istream&, Rational&);
		Rational operator+ (const Rational& ) const;
		Rational operator+ (long) const; 
		friend Rational operator+ (long, const Rational&);
};
#endif
Code:
//Rational.cpp

#include <iostream>
#include "Rational.h"
using namespace std;

Rational::Rational()
{
	_p = 1;
	_q = 1;
}

Rational::Rational ( long P, long Q )
{
     _p = P;
     _q = (Q == 0)? 1:Q;
}

Rational& Rational::operator= ( const Rational& R)
{
	_p = R._p;
	_q = R._q;
	return *this;
}

Rational& Rational::operator+= ( const Rational& R)
{
	_p = (_p * R._q) + (R._p * _q);
	_q *= R._q;
	return *this;
}

ostream& operator<< ( ostream& os, const Rational& R)
{
	os << R._p << "/" << R._q;
	return os;
}


istream& operator>> ( istream& is, Rational& R)
{
	char c;
	is >> R._p >> c >> R._q;
	return is;
}

Rational operator+ (long L, const Rational& R)
{
	Rational temp(L);
	return temp+=R;
}
Code:
Compile errors

Rational.o: In function `operator+(long, Rational const&)':
Rational.cpp:(.text+0x274): undefined reference to `Rational::Rational(Rational const&)'
Main.o: In function `main':
Main.cpp:(.text+0x345): undefined reference to `Rational::operator+(Rational const&) const'
collect2: ld returned 1 exit status
make: *** [Main] Error 1
I've tried it a few different ways, but I get compile errors each time. The member functions are given by my teacher and we're not allowed to change those.

I was thinking I could just do return += R, but that didn't work (error: expected primary-expression before â+=â token).

EDIT: I think I made some progress. In Rational.cpp, operator+ is now:

Code:
Rational operator+ (long L, const Rational& R)
{
	Rational temp(L);
	Rational x;
	x._p = temp._p += R._p;
	x._q = temp._q += R._q;
	return x;
}
But now I'm getting an error in my main.

Code:
#include <iostream>
#include "Rational.h"
using namespace std;

int main()
{
	Rational rat1(1, 2);
	Rational rat2(-20, 4);
           Rational x;

	//+
	cout << rat1 << " + " << rat2 << " = ";
	x = rat1+rat2;
	cout << x << endl;

	return 0;
}


COMPILE ERRORS

Main.cpp:(.text+0x345): undefined reference to `Rational::operator+(Rational const&) const'
collect2: ld returned 1 exit status
make: *** [Main] Error 1
:/ I was hoping to get this and add on the unary operators to finish this up tonight, but I've been stuck for a couple hours now.
__________________

System: Lancelot - 2008
CPU
Intel Q9550 E0 @ 4.03GHz (475x8.5)
Motherboard
eVGA 790i FTW SLI
Memory
2x2GB Corsair XMS3 DDR3
Graphics Card
2x eVGA Geforce GTX 285 in SLI
Hard Drive
128GB Falcon SSD, 2x1TB Caviar Black
Sound Card
ASUS Xonar D2
Power Supply
Corsair HX1000W
Case
Lian-Li A70B
CPU cooling
HDT-S1283; Ultra Kaze 3000 @ 2200RPM; Tuniq TX-2
GPU cooling
Stock fan
OS
Windows 7 Professional x64
Monitor
24" Samsung 2493HM

Last edited by stn0092 : 10-14-09 at 03:29 AM
stn0092 is offline   Reply With Quote
Old 10-14-09   #6 (permalink)
Case Modder
 
Spotswood's Avatar
 
Join Date: Jul 2008
Location: New Hampshire, USA
Posts: 236

Rep: 46 Spotswood is acknowledged by some
Unique Rep: 39
Trader Rating: 0
Default

You need to implement the copy constructor.
__________________
Rich
Custom Wooden Case Builder
Overclock.net Mod of the Month
Spotswood is offline   Reply With Quote
Old 10-14-09   #7 (permalink)
4.0 GHz
 
stn0092's Avatar
 
intel nvidia

Join Date: Jun 2008
Location: N. California
Posts: 603

Rep: 41 stn0092 is acknowledged by some
Unique Rep: 36
Trader Rating: 15
Default

Code:
#include <iostream>
#include "Rational.h"
using namespace std;

Rational::Rational()
{
	_p = 1;
	_q = 1;
}

Rational::Rational ( long P, long Q )
{
     _p = P;
     _q = (Q == 0)? 1:Q;
}

Rational& Rational::operator= ( const Rational& R)
{
	_p = R._p;
	_q = R._q;
	return *this;
}

Rational& Rational::operator+= ( const Rational& R)
{
	_p = (_p * R._q) + (R._p * _q);
	_q *= R._q;
	return *this;

}

ostream& operator<< ( ostream& os, const Rational& R)
{
	os << R._p << "/" << R._q;
	return os;
}


istream& operator>> ( istream& is, Rational& R)
{
	char c;
	is >> R._p >> c >> R._q;
	return is;
}

Rational& Rational::operator+ (const Rational& R) const
{
	_p = 1;
	_q = 1;
	return *this;
}

Rational& Rational::operator+ (long R) const
{	
	_p = 1;
	_q = 1;
	return *this;
}

Rational operator+ (long L, const Rational& R)
{
	Rational x(L);
	return x += R;
}
Quote:
Rational.o: In function `operator+(long, Rational const&)':
Rational.cpp:(.text+0x274): undefined reference to `Rational::Rational(Rational const&)'
Rational.o: In function `Rational::operator+(long) const':
Rational.cpp:(.text+0x29d): undefined reference to `Rational::Rational(Rational const&)'
Rational.o: In function `Rational::operator+(Rational const&) const':
Rational.cpp:(.text+0x2c5): undefined reference to `Rational::Rational(Rational const&)'
collect2: ld returned 1 exit status
make: *** [Main] Error 1
Where did I go wrong did now? :(
__________________

System: Lancelot - 2008
CPU
Intel Q9550 E0 @ 4.03GHz (475x8.5)
Motherboard
eVGA 790i FTW SLI
Memory
2x2GB Corsair XMS3 DDR3
Graphics Card
2x eVGA Geforce GTX 285 in SLI
Hard Drive
128GB Falcon SSD, 2x1TB Caviar Black
Sound Card
ASUS Xonar D2
Power Supply
Corsair HX1000W
Case
Lian-Li A70B
CPU cooling
HDT-S1283; Ultra Kaze 3000 @ 2200RPM; Tuniq TX-2
GPU cooling
Stock fan
OS
Windows 7 Professional x64
Monitor
24" Samsung 2493HM

Last edited by stn0092 : 10-14-09 at 09:12 AM
stn0092 is offline   Reply With Quote
Old 10-14-09   #8 (permalink)
Case Modder
 
Spotswood's Avatar
 
Join Date: Jul 2008
Location: New Hampshire, USA
Posts: 236

Rep: 46 Spotswood is acknowledged by some
Unique Rep: 39
Trader Rating: 0
Default

Quote:
Originally Posted by stn0092 View Post

Where did I go wrong did now?
You didn't implement the copy constructor:
Code:
Rational::Rational ( const Rational& o)
: _p(o._p), _q(o._q)
{
}
__________________
Rich
Custom Wooden Case Builder
Overclock.net Mod of the Month
Spotswood is offline   Reply With Quote
Old 10-14-09   #9 (permalink)
4.0 GHz
 
stn0092's Avatar
 
intel nvidia

Join Date: Jun 2008
Location: N. California
Posts: 603

Rep: 41 stn0092 is acknowledged by some
Unique Rep: 36
Trader Rating: 15
Default

Click below to show/hide Hidden Text Below!
Original post + a couple edits. This is irrelevant now unless you want to see what I did wrong.

Code:
Rational.h

#ifndef RATIONAL_H_DEF
#define RATIONAL_H_DEF

#include <iostream>
using namespace std;

class Rational
{
	long _p;
	long _q;

	public:

		Rational ( ); //default constructor 
		Rational ( long, long = 1 ); //constructor
		Rational ( const Rational& ); //copy constructor
		Rational& operator= ( const Rational& );
		Rational& operator+= ( const Rational& );
		Rational& operator-= ( const Rational& );
		Rational& operator*= ( const Rational& );
		Rational& operator/= ( const Rational& );

		friend ostream& operator<< ( ostream&, const Rational&);
		friend istream& operator>> ( istream&, Rational&);

		Rational operator+ (const Rational& ) const;
		Rational operator+ (long) const; 
		friend Rational operator+ (long, const Rational&);
};
#endif
Code:
//Rational.cpp
#include <iostream>
#include "Rational.h"
using namespace std;

Rational::Rational()
{
	_p = 1;
	_q = 1;
}

Rational::Rational ( long P, long Q )
{
     _p = P;
     _q = (Q == 0)? 1:Q;
}

Rational::Rational ( const Rational& R)
{
	_p = R._p;
	_q = R._q;
}
	
Rational& Rational::operator= ( const Rational& R)
{
	_p = R._p;
	_q = R._q;
	return *this;
}

Rational& Rational::operator+= ( const Rational& R)
{
	_p = (_p * R._q) + (R._p * _q);
	_q *= R._q;
	return *this;
}

Rational& Rational::operator-= ( const Rational& R)
{
	_p = (_p * R._q) - (R._p * _q);
	_q = (_q * R._q);
	return *this;
}

Rational& Rational::operator*= ( const Rational& R)
{
	_p = _p * R._p;
	_q = _q * R._q;
	return *this;
}

Rational& Rational::operator/= ( const Rational& R)
{
	_p = _p * R._q;
	_q = _q * R._p;
	return *this;
}

ostream& operator<< ( ostream& os, const Rational& R)
{
	os << R._p << "/" << R._q;
	return os;
}


istream& operator>> ( istream& is, Rational& R)
{
	char c;
	is >> R._p >> c >> R._q;
	return is;
}

Rational::Rational operator+ (const Rational& R)
{
	_p = R._p;
	_q = R._q;

//ERRORS IN THESE TWO LINES.
}

Rational operator+ (long L, const Rational& R)
{
	return (L)+=(R);
}
Code:
//Main.cpp 

#include <iostream>
#include "Rational.h"
using namespace std;

int main()
{
	Rational rat1(1, 2);
	Rational rat2(-20, 4);
	Rational temp;

	//+
	temp = rat1;
	cout << rat1 << " + " << rat2 << " = ";
	temp = rat1+rat2;
	cout << temp << endl;

	return 0;
}
Quote:
Rational.cpp: In function âRational operator+(const Rational&)â:
Rational.cpp:78: error: â_pâ was not declared in this scope
Rational.h:13: error: âlong int Rational::_pâ is private
Rational.cpp:78: error: within this context
Rational.cpp:79: error: â_qâ was not declared in this scope
Rational.h:14: error: âlong int Rational::_qâ is private
Rational.cpp:79: error: within this context
Rational.cpp: In function âRational operator+(long int, const Rational&)â:
Rational.cpp:84: error: no match for âoperator+=â in âL += Râ
I still get that compile error. Something wrong with that function...? How should I write that one?


Okay. Everything compiles, but isn't functioning correctly. My + gives me an answer of -16/4 (reducing the fraction is not required in this assignment) instead of some value equivalent of -9/2 and I can't find what I did wrong (yet again...). My += does give me a correct equivalent value of -36/8.

EDIT: I can see that I wrote Rational Rational::operator+ (const Rational& R)const incorrectly...what should I put in there instead? return R;?

Code:
//Rational.h

#ifndef RATIONAL_H_DEF
#define RATIONAL_H_DEF

#include <iostream>
using namespace std;

class Rational
{
	long _p;
	long _q;

	public:

		Rational ( ); //default constructor 
		Rational ( long, long = 1 ); //constructor
		Rational ( const Rational& ); //copy constructor
		Rational& operator= ( const Rational& );
		Rational& operator+= ( const Rational& );
		Rational& operator-= ( const Rational& );
		Rational& operator*= ( const Rational& );
		Rational& operator/= ( const Rational& );

		friend ostream& operator<< ( ostream&, const Rational&);
		friend istream& operator>> ( istream&, Rational&);

		Rational operator+ (const Rational&) const;
		Rational operator+ (long) const; 
		friend Rational operator+ (long, const Rational&);
};
#endif
Code:
//Rational.cpp

#include <iostream>
#include "Rational.h"
using namespace std;

Rational::Rational()
{
	_p = 1;
	_q = 1;
}

Rational::Rational ( long P, long Q )
{
     _p = P;
     _q = (Q == 0)? 1:Q;
}

Rational::Rational ( const Rational& R)
{
	_p = R._p;
	_q = R._q;
}
	
Rational& Rational::operator= ( const Rational& R)
{
	_p = R._p;
	_q = R._q;
	return *this;
}

Rational& Rational::operator+= ( const Rational& R)
{
	_p = (_p * R._q) + (R._p * _q);
	_q *= R._q;
	return *this;
}

ostream& operator<< ( ostream& os, const Rational& R)
{
	os << R._p << "/" << R._q;
	return os;
}


istream& operator>> ( istream& is, Rational& R)
{
	char c;
	is >> R._p >> c >> R._q;
	return is;
}

Rational Rational::operator+ (const Rational& R)const
{
	Rational t;
	t+=R;
	return t;
}

Rational operator+ (long L, const Rational& R)
{
	return Rational(L)+=(R);
}
Code:
//Main.cpp

#include <iostream>
#include "Rational.h"
using namespace std;

int main()
{
	Rational rat1(1, 2);
	Rational rat2(-20, 4);
	Rational temp;

	//+=
	temp = rat1;
	cout << rat1 << " += " << rat2 << " = ";
	temp+=rat2;
	cout << temp << endl;

	//+
	temp = rat1;
	cout << rat1 << " + " << rat2 << " = ";
	temp = (rat1)+(rat2);
	cout << temp << endl;

	return 0;
}
__________________

System: Lancelot - 2008
CPU
Intel Q9550 E0 @ 4.03GHz (475x8.5)
Motherboard
eVGA 790i FTW SLI
Memory
2x2GB Corsair XMS3 DDR3
Graphics Card
2x eVGA Geforce GTX 285 in SLI
Hard Drive
128GB Falcon SSD, 2x1TB Caviar Black
Sound Card
ASUS Xonar D2
Power Supply
Corsair HX1000W
Case
Lian-Li A70B
CPU cooling
HDT-S1283; Ultra Kaze 3000 @ 2200RPM; Tuniq TX-2
GPU cooling
Stock fan
OS
Windows 7 Professional x64
Monitor
24" Samsung 2493HM

Last edited by stn0092 : 10-14-09 at 05:09 PM
stn0092 is offline   Reply With Quote
Old 10-14-09   #10 (permalink)
4.0 GHz
 
dharmaBum's Avatar
 
intel nvidia

Join Date: Apr 2007
Location: Raleigh, NC
Posts: 747

Rep: 121 dharmaBum is acknowledged by manydharmaBum is acknowledged by many
Unique Rep: 89
Trader Rating: 0
Default

Code:
Rational Rational::operator+ (const Rational& R)const
{
	Rational t;
	t+=R;
	return t;
}
Think about it: what is "t" equal to here?

Hint: What is being added to your input (-20/4) to give as output (-16/4)?
__________________
3DMark06: 19091 - 3DMark Vantage: P15264 - SuperPi: 10.968s

Programming Quote of the Day:
Bjarne Stroustrup:
Quote:
There are only two industries that refer to their customers as ‘users’.

System: Europa
CPU
E8500 4.36ghz @ 1.36v
Motherboard
EVGA 780i SLi P05 Bios
Memory
G.SKILL 4GB(2x2GB) @ 924MHz (5-4-4-12-2T)
Graphics Card
2xEVGA 8800GTS (G92) 512MB @800/2000/2110
Hard Drive
Seagate 500gbx2, (fake-)RAID0
Sound Card
Sound Blaster X-Fi XtremeGamer
Power Supply
CORSAIR 1000HX 1000W
Case
Gigabyte GZ-FA2CA-AJB Black Aluminum
CPU cooling
TDX 775 Block, 360 BlackIce rad
GPU cooling
MAZE5x2, TT copper HS
OS
Fedora10-86_64/Vista64
Monitor
22" Samsung SyncMaster 2232BW

Last edited by dharmaBum : 10-14-09 at 05:31 PM
dharmaBum is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -5. The time now is 01:11 PM.


Overclock.net is a Carbon Neutral Site Creative Commons License

Terms of Service / Forum Rules | Privacy Policy | DMCA Info | Advertising | Become an Official Vendor
Copyright © 2009 Shogun Interactive Development. Most rights reserved.
Page generated in 0.20005 seconds with 8 queries