简体   繁体   English

使用成员初始值设定项列表没有匹配的函数调用错误

[英]No matching function call error using member initializer list

I have 2 classes : point and droite .我有 2 个类: pointdroite

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.

相关问题 每个构造函数成员初始化器列表的 const 数据成员的初始化,错误:没有匹配的 function 用于调用 - Initialization of const data members per constructor member-initializer list, error: no matching function for call 使用std :: min时发生错误“没有匹配函数调用&#39;min( <brace-enclosed initializer list> )“” - Error when using std::min “no matching function for call to ‘min(<brace-enclosed initializer list>)’” 错误:没有匹配的 function 调用 'std::vector<pet*> ::向量(<brace-enclosed initializer list> )'</brace-enclosed></pet*> - error: no matching function for call to 'std::vector<Pet*>::vector(<brace-enclosed initializer list>)' 向量错误:没有匹配的成员函数调用插入 - Vector error: no matching member function call to insert 错误:没有匹配的成员 function 可以调用“推送” - error: no matching member function for call to 'push' 没有匹配的成员函数来调用“连接”-使用“ this”时 - No Matching Member Function to Call 'connect' - When Using 'this' 在初始化列表中使用复杂函数来初始化const成员一个好的设计? - Is using a complex function in initializer list to initialize const member a good design? 模板化的成员函数调用g ++错误:没有匹配的调用函数 - Templated member function call g++ error : no matching function for call 错误:没有匹配的 function 调用 'uWS::TemplatedApp<false> ::ws<main()::userdata> (常量字符 [3],<brace-enclosed initializer list> )'</brace-enclosed></main()::userdata></false> - error: no matching function for call to 'uWS::TemplatedApp<false>::ws<main()::UserData>(const char [3], <brace-enclosed initializer list>)' 正确的线程调用语法? 错误:没有匹配调用std :: thread :: thread( <brace-enclosed initializer list> ) - Proper thread call syntax? error: no matching call to std::thread::thread(<brace-enclosed initializer list>)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM