Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Inherit problem in the class



  • Hi everyone,

    I am new in Qt world :)

    I created 2 class one inherit from the other one. Please find below my code :

    #include "cclass2.h"
    
    
    class CClass1
    {
    public:
        explicit CClass1(CClass2& p_class);
        ~CClass1();
    public: // Data
     
    protected:
        CClass2& p_class2;
    
    };
    

    but I get the error : expected ')' before '&' token explicit CClass1(CClass2& snapshot);

    any help please



  • @mena_mes

    This has nothing to do with Qt. It's just plain C++

    Where exactly do you get this error? In your class header or when create an instance of it?



  • @mena_mes said in Inherit problem in the class:

    but I get the error : expected ')' before '&' token explicit CClass1(CClass1& snapshot);

    The code snippet mentioned in the error message does not exist in the code you posted. Start by looking for the code that matches the error message; possibly in the C++ source providing the implemenation.


  • Lifetime Qt Champion

    @mena_mes In the code you posted I don't see any inheritance.
    Does CClass2 inherit from CClass1?
    Does cclass2.h include cclass1.h? If so you have circular dependency. Change

    CClass2& p_class2;
    

    to

    CClass2 *p_class2;
    

    Remove

    #include "cclass2.h"
    

    and add

    class CClass2; // Forward declaration
    

    before CClass1 declaration.
    And as already pointed out: this has nothing to do with Qt.


Log in to reply