SOLVED: Problem: Using a variable of other class

I guess my problem is easy to solve but I'm newbie for C++ so I don't get it:

I have 2 classes, ClassA and ClassB. ClassA has a variable and its value is needed to be read by ClassB. But I'll get an error. Here's my code:

//classA.h:
1
2
3
4
public:
  static int GetParameter();
private:
  static int parameter; //I added static here 


//classA.cpp:
1
2
3
int ClassA::GetParameter() {
  return parameter;
}


//classB.h:
#include "classA.h"

//classB.cpp:
1
2
int result = ClassA::GetParameter();
//this call gives me an error: illegal reference to non-static member function 'ClassA::parameter' 


What I'm doing wrong here?
Last edited on
You should also have parameter to be static
Thank you, now the compiling is ok but...

Now I have linking error:

classA.obj : error LNK2001: unresolved external symbol "private: static int ClassA::parameter"

Any ideas to this new problem?
Last edited on
Problem solved, I haven't created an instance for ClassA object. Such a newbie mistake.
Last edited on
Topic archived. No new replies allowed.