0

Is it proper to initialize my static member variable in the constructor class?

// CFoo.h
class CFoo
{
public:
    CFoo();
    ~CFoo();
    static std::string str;
};

// CFoo.cpp
CFoo::CFoo()
{
    str = "HELLO";
}

CFoo::~CFoo()
{
}

Thanks

domlao
  • 15,145
  • 32
  • 90
  • 128

1 Answers1

1

You haven't define static member yet. You need to define it in CFoo.cpp.

CFoo.cpp

std::string CFoo::str;  // define str

CFoo::CFoo()

{
    str = "HELLO";  // reset str is fine
}

CFoo::~CFoo()
{
}
billz
  • 43,318
  • 8
  • 77
  • 98