Static member

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ycinar
    New Member
    • Oct 2007
    • 39

    Static member

    I have static member in a class, say class A, in class A i have a static bool attribute xyz. Then I have another class, class B. In class B, I wanna set A::xyz=true;

    but compiler gives 2 errors:

    error LNK2001: unresolved external symbol "private: static bool...
    fatal error LNK1120: 1 unresolved externals

    Has anyone got any idea how to get around this?
  • Cucumber
    New Member
    • Sep 2007
    • 90

    #2
    The static variable is declared as private, so its not available outside class A.
    Declare it as public if you want to class B to use it or make Class B a friend class of A´s.


    Also dont forget to declare the static variable somewhere in your source code.
    I.e.
    Code:
    bool classA::xyz = true;

    Comment

    Working...