开发者

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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜