Term
class Object { public: static int counter; };
int main() { cout << Object::counter; }
|
|
Definition
ERROR
static variables need to be initialized, outside of the class definition
|
|
|
Term
class Object { public: static int counter = 0; };
int main() { cout << Object::counter; }
|
|
Definition
ERROR
static variables NEED to be defined OUTSIDE class definition |
|
|
Term
class Object { public: static int counter = 0; };
Object::counter = 0;
int main() { cout << Object::counter; }
|
|
Definition
ERROR,
need to state data type |
|
|
Term
class Object { public: static int counter = 0; };
int Object.counter = 0;
int main() { cout << Object::counter; }
|
|
Definition
ERROR,
need to use :: scope |
|
|
Term
class Object { public: static int counter; };
int Object::counter = 0;
int main() { cout << Object::counter; }
|
|
Definition
|
|
Term
class Object { public: static int counter; }P0;
int Object::counter = 0;
int main() { cout << P0::counter; }
|
|
Definition
ERROR, instances need to use .counter |
|
|
Term
class Object { public: static int counter; }P0;
int Object::counter = 0;
int main() { cout << P0.counter; }
|
|
Definition
|
|
Term
class Object { public: static int counter; Object() {counter++;} };
int Object::counter = 0;
int main() { Object obj, obj2, obj3; cout << obj.counter << endl; obj.counter++; cout << obj2.counter << endl; Object::counter++; cout << obj3.counter << endl; }
|
|
Definition
|
|
Term
class Object { public: static int counter; int id; Object() {id = counter++;} };
int Object::counter = 0;
int main() { Object obj, obj2, obj3; cout << obj.id << endl; obj.id++; cout << obj2.id << endl; Object::counter++; cout << obj3.id << endl; }
|
|
Definition
|
|
Term
class Object { public: static int counter; int id; Object() {id = counter++;} };
int Object::counter = 0;
int main() {
cout << Object::counter << endl; Object objs[100]; cout << Object::counter << endl; }
|
|
Definition
|
|
Term
class Object { public: static int counter; int id; };
int main() { Object obj; }
|
|
Definition
Compiles
counter wasnt referenced yet so no issues in runtime. counter needs to be initialized. |
|
|
Term
class Object { public: static int counter; int id; Object() { id = counter++; } };
int Object::counter = 0;
class Subject { public: static Object obj; };
int main() { Subject s1; s1.obj.id = 1; }
|
|
Definition
ERROR
Subject::obj wasnt initialized
|
|
|