I have declared a static variable in a file say "example.hxx" and am calling this variable in the cxx file "example.cxx" in this way example.hxx file :-
class example{
private:
static int p;
public:
void func();
};
CXX file
#include <example.hxx>
class example{
void func(){
std::cout<<p;
}
}
I get an error of undefined reference to p. Why does this happen and how to solve this ? I have seen some answers in relation to this question but none deals with separate hxx and cxx files, instead they answer wrt main function. Would be great if someone clears my doubt !