none
static variable RRS feed

  • Question

  • I am trying to compile a class that has a static member variable.
    but I keep getting linkage errors like this:

    Error    1    error LNK2005: "private: static bool CommentText::visibility" (?visibility@CommentText@@0_NA) already defined in main.obj    counter.obj   

    I cant find where is the double definition is.

    any ides?

    thanks.
    Einat


    Saturday, December 6, 2008 11:15 AM

Answers

  • Put the definition of the static member in a .cpp file, not a .h file.  The declaration belongs in the .h file, where you got it.
    Hans Passant.
    • Marked as answer by EinZuk Saturday, December 6, 2008 12:19 PM
    Saturday, December 6, 2008 11:28 AM
    Moderator

All replies

  • Put the definition of the static member in a .cpp file, not a .h file.  The declaration belongs in the .h file, where you got it.
    Hans Passant.
    • Marked as answer by EinZuk Saturday, December 6, 2008 12:19 PM
    Saturday, December 6, 2008 11:28 AM
    Moderator
  • thank you.
    it worked great.
    einat

    Saturday, December 6, 2008 12:20 PM