I am trying to reach a static variable declared in MyClass.h from MyClass.cpp. But I get following errors. I made a research but still have no clue why my code does not compile. I use visual studio 2013.
MyClass.h
#ifndef __MyClass_h_
#define __MyClass_h_
class MyClass {
static int x;
public:
static int y;
};
#endif
MyClass.cpp
#include "MyClass.h"
void MyClass::sor() (const string& var1, const unsigned count) const {
// What goes here? See below for what I have tried
}
So, if I use:
int MyClass::x=8;
This says int MyClass::x redefinition
and MyClass::x 'MyClass::x' : definition or redeclaration illegal in current scope
If I use:
MyClass::x=8;
This gives the error 1 unresolved external
.
If I use:
MyClass::y=8;
This also gives the error 1 unresolved external
.
If I use:
int MyClass::y=8;
This says int MyClass::y redefinition
and 'MyClass::y' : definition or redeclaration illegal in current scope