Static Class Members Giving Me Grief

Not to sure how to use static members in a class. Wont give you my actual code but an example of what I want and what I need to change in order to get this to work.

1
2
3
4
5
6
7
8
9
10
11
12
class.h

class MyClass
{
  public:
    MyClass();
    ~MyClass();

    static LONGLONG s_SomeValue;

    void DoSomething();
};


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class.cpp

MyClass::MyClass()
{
  LONGLONG MyClass::s_someValue = 0;
}

MyClass::~MyClass()
{
}

void MyClass::DoSomething()
{
  //Etc something like:
  QueryPerformanceCounter( (LARGE_INTEGER*) MyClass::s_SomeValue);
}


1
2
3
4
5
main.cpp

MyClass foo;

foo.DoSomething();


Nothing close to the code i'm creating but its what I want - the layout like this. But I'm getting constant linker errors with the static value.

So little stumped what to do :(
The static values shouldn't be initialized in the constructor but outside the class scope

http://www.cplusplus.com/doc/tutorial/classes2.html#static
Last edited on
I've seen it done like before and understand it that way. But - it's not possible to do it my way?

I'm still happy to create it outside the class scope but if i do. Will

1
2
3
4
5
void MyClass::DoSomething()
{
  //Etc something like:
  QueryPerformanceCounter( (LARGE_INTEGER*) MyClass::s_SomeValue);
}



work? If not how can I make it so that would work? Sorry just I'm heading to bed so leaving this message here before I pop in :)

Cheers Bazzy ;)
I think the correct syntax should be QueryPerformanceCounter( (LARGE_INTEGER*) &MyClass::s_SomeValue);
[Edit: ] erased all this post, all is explained clearly in

http://www.cplusplus.com/doc/tutorial/classes2.html#static
Last edited on
Alright cheers Bazzy and titon, will give it a shot now and see if it works for me.

And my mistake for not including the &, my original program had it but forgot to include it for this example haha :)

Thanks
Topic archived. No new replies allowed.