views:

188

answers:

1

With the following code, I keep getting error C2535 when I compile. It's complaining that a member function already defined or declared.

Rationnel.h

...
class Rationnel
{   
public:
Rationnel(int); //Constructor
Rationnel(int,int); //Constructor
void add(const Rationnel);
...

Rationnel.cpp

...
//Constructor
Rationnel::Rationnel(int n = 1)
{
    numerateur = n;
    denominateur = 1;
}

//Constructor
Rationnel::Rationnel(int n = 1, int d = 1)
{
    numerateur = n;
    denominateur = d;
}
...

Any idea what could be causing the error?

Thanks for your time.

+2  A: 

If you write Rationnel (5), how do you know which one of the following will be called ? Both can be used so an error occurs.

Rationnel::Rationnel(int n = 1)
Rationnel::Rationnel(int n = 1, int d = 1)
Phong
Thanks. I got it to work by removing the default values.
PuRe_ChAoS12
@PuRe_ChAoS12 - In addition to having the most annoying name I've ever had to type, you could achieve the same effect by simply taking out the `Rationnel::Rationell(int)` version.
Chris Lutz
Thanks Chris Lutz, this helped me alot as well.
PuRe_ChAoS12