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

'defaultHealthCalc' is not a member of 'GameStuff'



  • Hello!

    Why I received this message:

    bq. GameCharacter.h:13: error: 'defaultHealthCalc' is not a member of 'GameStuff'
    explicit GameCharacter( std::string name, HealthCalcFunc hcf = GameStuff::defaultHealthCalc )

    There are all my files. Please, help me!

    GameCharacter.h
    [code]
    #ifndef GAMECHARACTER_H
    #define GAMECHARACTER_H

    #include <string>
    #include "functionsForHealthCalc.h"

    namespace GameStuff {

    class GameCharacter {
    public:
        typedef int (*HealthCalcFunc)(const GameCharacter&);
    
        explicit GameCharacter( std::string name, HealthCalcFunc hcf = GameStuff::defaultHealthCalc )
        {
        }
    
    };
    

    }

    #endif // GAMECHARACTER_H
    [/code]

    functionsForHealthCalc.h
    [code]
    #ifndef FUNCTIONS_FOR_HEALTHCALC_H
    #define FUNCTIONS_FOR_HEALTHCALC_H

    #include "GameCharacter.h"

    namespace GameStuff {

    class GameCharacter;
    
    int defaultHealthCalc( const GameCharacter& gc );
    

    }

    #endif // FUNCTIONS_FOR_HEALTHCALC_H
    [/code]

    functionsForHealthCalc.cpp
    [code]
    #include "functionsForHealthCalc.h"

    namespace GameStuff {

    int defaultHealthCalc( const GameCharacter& gc ) {
        return 1;
    }
    

    }
    [/code]

    Question.pro
    [code]
    SOURCES +=
    main.cpp
    functionsForHealthCalc.cpp

    HEADERS +=
    GameCharacter.h
    functionsForHealthCalc.h
    [/code]

    main.cpp
    [code]
    #include <iostream>

    int main() {

    return 0;
    

    }
    [/code]


  • Lifetime Qt Champion

    Hi,

    I'd say circular dependencies, your are including functionsForHealthCalc.h in GameCharacter.h and GameCharacter.h in functionsForHealthCalc.h.

    Just remove GameCharacter.h in functionsForHealthCalc.h since you don't need it.


Log in to reply