Issue declaring extern class object

后端 未结 4 1100
孤街浪徒
孤街浪徒 2020-12-21 12:37

Let me start by saying I\'ve extensively searched for answers on google and more specifically here.

The thing is I actually (at least I think I did) found people wit

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-21 12:47

    "extern Player john;" is considered to be undefined identifier as the compiler is unable to understand what Player is, as you have not included the file Player.cpp where the class Player is declared to cc.h . It is always recommended to declare the class and its methods in header files say for example in Player.h and then define these methods in the source file i.e Player.cpp. And to include Player.h in your cc.h so that compiler understands where " Player john;" is declared.

提交回复
热议问题