Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. 'defaultHealthCalc' is not a member of 'GameStuff'
Forum Updated to NodeBB v4.3 + New Features

'defaultHealthCalc' is not a member of 'GameStuff'

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 545 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • 8Observer88 Offline
    8Observer88 Offline
    8Observer8
    wrote on last edited by
    #1

    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]

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved