//foo.h
class Foo
{
private:
static int number;
public:
static int bar();
};
//foo.cc
#include "foo.h"
int Foo::bar()
{
return Foo::number;
}
this is not working. I want to define a static function outside the class definition and access a static value.
undefined reference to `Foo::number'
You just declared the static member you need to define it too.
Add this in your cpp file.
This should be a good read:
what is the difference between a definition and a declaration?