Results 1 to 3 of 3

Thread: 'defaultHealthCalc' is not a member of 'GameStuff'

  1. #1
    Join Date
    Nov 2012
    Posts
    232
    Thanks
    118
    Thanked 18 Times in 10 Posts
    Platforms
    Windows Android

    Default 'defaultHealthCalc' is not a member of 'GameStuff'

    Hello!

    Why I received this message:
    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
    Qt Code:
    1. #ifndef GAMECHARACTER_H
    2. #define GAMECHARACTER_H
    3.  
    4. #include <string>
    5. #include "functionsForHealthCalc.h"
    6.  
    7. namespace GameStuff {
    8.  
    9. class GameCharacter {
    10. public:
    11. typedef int (*HealthCalcFunc)(const GameCharacter&);
    12.  
    13. explicit GameCharacter( std::string name, HealthCalcFunc hcf = GameStuff::defaultHealthCalc )
    14. {
    15. }
    16.  
    17. };
    18. }
    19.  
    20. #endif // GAMECHARACTER_H
    To copy to clipboard, switch view to plain text mode 

    functionsForHealthCalc.h
    Qt Code:
    1. #ifndef FUNCTIONS_FOR_HEALTHCALC_H
    2. #define FUNCTIONS_FOR_HEALTHCALC_H
    3.  
    4. #include "GameCharacter.h"
    5.  
    6. namespace GameStuff {
    7.  
    8. class GameCharacter;
    9.  
    10. int defaultHealthCalc( const GameCharacter& gc );
    11. }
    12.  
    13. #endif // FUNCTIONS_FOR_HEALTHCALC_H
    To copy to clipboard, switch view to plain text mode 

    functionsForHealthCalc.cpp
    Qt Code:
    1. #include "functionsForHealthCalc.h"
    2.  
    3. namespace GameStuff {
    4.  
    5. int defaultHealthCalc( const GameCharacter& gc ) {
    6. return 1;
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 

    Question.pro
    Qt Code:
    1. SOURCES += \
    2. main.cpp \
    3. functionsForHealthCalc.cpp
    4.  
    5. HEADERS += \
    6. GameCharacter.h \
    7. functionsForHealthCalc.h
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    Qt Code:
    1. #include <iostream>
    2.  
    3. int main() {
    4.  
    5. return 0;
    6. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by 8Observer8; 26th April 2014 at 19:26.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: 'defaultHealthCalc' is not a member of 'GameStuff'

    Try removing line 4 from functionsForHealthCalc.h. Line 8 makes the include is unnecessary

    When the compiler is given functionsForHealthCalc.cpp to compile it includes GameCharacter.h before it declares defaultHealthCalc(). GameCharacter.h tries to reference defaultHealthCalc() which has not yet been declared.

  3. The following user says thank you to ChrisW67 for this useful post:

    8Observer8 (27th April 2014)

  4. #3
    Join Date
    Nov 2012
    Posts
    232
    Thanks
    118
    Thanked 18 Times in 10 Posts
    Platforms
    Windows Android

    Default Re: 'defaultHealthCalc' is not a member of 'GameStuff'

    Thank you very much!

Similar Threads

  1. Replies: 2
    Last Post: 28th March 2012, 21:47
  2. Replies: 2
    Last Post: 23rd February 2012, 12:23
  3. Replies: 22
    Last Post: 8th October 2008, 13:54
  4. member
    By mickey in forum General Programming
    Replies: 2
    Last Post: 28th July 2006, 19:37
  5. Hey everyone - new member
    By CuCullin in forum General Discussion
    Replies: 16
    Last Post: 14th February 2006, 16:59

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.