Issue declaring extern class object

后端 未结 4 1087
孤街浪徒
孤街浪徒 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条回答
  •  -上瘾入骨i
    2020-12-21 12:51

    1. You need to define the Player class, in your header file
    2. Use extern to use variable that has an external linkage, and is already defined in some other file.

    For example: you have file a.cpp, and inside this file has a global variable Player p. If you want to use the same exact instance p of Player in file c.cpp, then inside file c.cpp you write extern Player p.

    I hope i made myself clear.

提交回复
热议问题