Archived

This topic is now archived and is closed to further replies.

static members of a class

This topic is 5620 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a static member of my class CFace, defined inside the class declaration file as: static int m_UniqueID; and just below the class declaration: int CFace::m_UniqueID = 0; However I get the following errors when linking: Compiling... Brush.cpp Face.cpp Polygon.cpp PolygonManager.cpp Vertex.cpp PolygonTabDB.cpp TextureTabDB.cpp MessageProcs.cpp Application.cpp Engine.cpp main.cpp Linking... Face.obj : error LNK2005: "public: static int CFace::m_UniqueID" (?m_UniqueID@CFace@@2HA) already defined in Brush.obj Polygon.obj : error LNK2005: "public: static int CFace::m_UniqueID" (?m_UniqueID@CFace@@2HA) already defined in Brush.obj PolygonManager.obj : error LNK2005: "public: static int CFace::m_UniqueID" (?m_UniqueID@CFace@@2HA) already defined in Brush.obj Vertex.obj : error LNK2005: "public: static int CFace::m_UniqueID" (?m_UniqueID@CFace@@2HA) already defined in Brush.obj PolygonTabDB.obj : error LNK2005: "public: static int CFace::m_UniqueID" (?m_UniqueID@CFace@@2HA) already defined in Brush.obj TextureTabDB.obj : error LNK2005: "public: static int CFace::m_UniqueID" (?m_UniqueID@CFace@@2HA) already defined in Brush.obj MessageProcs.obj : error LNK2005: "public: static int CFace::m_UniqueID" (?m_UniqueID@CFace@@2HA) already defined in Brush.obj Application.obj : error LNK2005: "public: static int CFace::m_UniqueID" (?m_UniqueID@CFace@@2HA) already defined in Brush.obj Engine.obj : error LNK2005: "public: static int CFace::m_UniqueID" (?m_UniqueID@CFace@@2HA) already defined in Brush.obj main.obj : error LNK2005: "public: static int CFace::m_UniqueID" (?m_UniqueID@CFace@@2HA) already defined in Brush.obj Release/Model.exe : fatal error LNK1169: one or more multiply defined symbols found Error executing link.exe. Creating browse info file... Model.exe - 11 error(s), 0 warning(s) Whats up with that?

Share this post


Link to post
Share on other sites
int CFace::m_UniqueID = 0;

You should put this in the CFace class constructor in the implementation file (cpp) not after the class declaration in the header.


No matter where you go. &this (not mine)

Share this post


Link to post
Share on other sites
quote:
Original post by Martee
[quote]Original post by Mulligan
int CFace::m_UniqueID = 0;


This is in a header, right? It should go in a source file.

Bingo!

Share this post


Link to post
Share on other sites