I am trying:
class MyClass {
public:
MyClass();
int myID;
static int currentID;
};
MyClass::MyClass() {
myID = currentID;
++currentID;
}
I’m trying to assign a unique ID to all the instances of this class.
Edit:
It doesn’t work for me. I get two of these in xcode:
Undefined symbols:
“GameObject::currentID”, referenced from:
__ZN10GameObject9currentIDE$non_lazy_ptr in GameObject.o
(maybe you meant: __ZN10GameObject9currentIDE$non_lazy_ptr)
ld: symbol(s) not found
collect2: ld returned 1 exit status
It works for me:
Output: