C++ Duplicate Symbol error when defining static class variable in XCode -


I have a static class member who has increased the constructor. According to the rules, it is declared in the classroom and defined outside. It should be completely legal Any ideas why I am getting a duplicate symbol error?

  class player {Personal: Static In Newsplayer; Public: Player () {numPlayers ++; }}; Inte Player: :: numplayers = 0;  

The problem is that you are not separating your partitions with your definition. Consider:

 Class Player {Private: Stable in Newplayer; Public: Player () {numPlayers ++; }}; 

The above code only announces the existence of "numplayers" in the "player", however, "player :: numplayers" does not reserve any place or assigns memory address. However:

 int player :: numplayers = 0; 

The above code is a definition - it reserves the space for the object player :: numplayers and specifies a unique address for that object. Such a program violates a rule-rule once it appears more than once. What is most likely happening now that you are including this file ...

You can always use ".c", ".cpp", ".m", ".mm" or "Any other" source "file (i.e. file containing definitions) should include only" header "files (i.e. files with purely declarations). For many build systems including Xcode, each source file itself is compiled Is involved in the project and if you If you include a source file from another source file, the definitions are linked twice - firstly when it is referenced by another source file, then it is compiled and then re-compiled.

Since you are asking about Xcode ... You can solve this problem by unchecking the source file in the project's expansion scene; A source indicates a check mark near the file It will be compiled and linked to the current goal. However, I firmly recommend that you leave your ".mm" file, create an ".h" file in which you place your announcements, and a source Instead of adding the file to another, include the ".h" file.


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -