Multiple constructors definitions with same name but different signatures (C++)
With the following code, I keep getting error C2535 when I compile. It's complaining that a member 开发者_JS百科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.
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)
精彩评论