no matching function for call to 'ParentClass::ParentClass' error in derived class constructor



  • Hey,
    First: I am pretty sure, this is just a tiny mistake, but I am unfortunately stuck right now...
    When I compile my program, I get the error from the title in the cpp constructor of a class ("FunctionNode") that derives from another class ("Node").
    The parent class is ok, everything works, I just get the error in the derived class.
    Here the class header:

    #ifndef FUNCTIONNODE_H
    #define FUNCTIONNODE_H
    
    #include "node.h"
    class FunctionNode : public Node
    {
    public:
        FunctionNode();
    };
    #endif // FUNCTIONNODE_H
    
    

    and the source file:

    #include "functionNode.h"
    FunctionNode::FunctionNode(){} // error here
    
    

    error:

    error: no matching function for call to 'Node::Node()'
     FunctionNode::FunctionNode()
    

    What did I miss?
    Thanks for answers


  • Moderators

    You did not initialize the parent class, so compiler tries to automatically initialize it using default constructor Node(), but it is missing.

    You should initialize the parent class manually:

    FunctionNode::FunctionNode() : Node(some, arguments) {}
    

    Or add a default constructor to Node class.



  • @sierdzio Ahh, yes, thanks, I wondered, that it worked with some QObject classes this way, but I forgot to add all default values for arguments in the Node constructor, that I may can not give at this point but later in the program (or calling them with default values here).
    Thanks!


  • Moderators

    Happy coding!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.