[英]No matching function call error using member initializer list
I have 2 classes : point
and droite
.我有 2 个类: point
和droite
。
Header file for Point:点的头文件:
class point
{
int abs,ord;
public:
point(int,int);
~point();
};
cpp file for Point点的 cpp 文件
point::point(int a,int b):abs(a),ord(b)
{
cout<<"++ constructor point "<<abs<<" "<<ord<<endl;
}
point::~point()
{
cout<<"-- destruction abs= "<<abs<<"et ord= "<<ord<<endl;
}
Header file for Droite: Droite 的头文件:
class droite: public point{
point s1;
point s2;
public:
droite(int,int,int,int);
~droite();
};
cpp file for Droite Droite 的 cpp 文件
droite::droite(int a,int b,int c,int d):s1(a,b),s2(c,d)
{
cout<<"++ constructor of droite "<<a<<""<<b<<""<<c<<""<<d<<endl;
}
droite::~droite(){ cout<<"destructor of droite "<<endl;}
And main和主要
int main(){
droite A(1,2,3,4);
}
The ouput is :输出是:
droite.cpp|12| droite.cpp|12| error: no matching function for call to 'point::point()'错误:没有用于调用“point::point()”的匹配函数
My question is: why am I getting this error while there's a constructor with arguments for point?我的问题是:当有一个带点参数的构造函数时,为什么我会收到这个错误?
There seems to be no good reason why you define droite
as being derived from point
, and then have two point
members of droite
.似乎没有充分的理由将droite
定义为从point
派生,然后有两个droite
point
成员。 However, if you do need this derivation, then you will need an explicit call to the base class ( point
) constructor with the two int
arguments in your definition of the driote
constructor:但是,如果您确实需要这种推导,那么您将需要在driote
构造函数的定义中使用两个int
参数显式调用基类 ( point
) 构造函数:
droite::droite(int a, int b, int c, int d) : point(0,0), s1(a, b), s2(c, d)
{
cout << "++ constructor of droite " << a << "" << b << "" << c << "" << d << endl;
}
This looks like a syntax error.这看起来像是一个语法错误。 I'm not sure why you are redeclaring public point
in your droite header file.我不确定您为什么要在 droite 头文件中重新声明public point
。
class droite: public point{
point s1;
point s2;
public:
droite(int,int,int,int);
~droite();
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.