Why should we define static member variable outside the class? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why should we define static member variable outside the class?

Static variables are initialized to 0 and defined after class definition. So, why compiler don't show error like "...was not defined in this scope"?

15th Apr 2017, 4:56 PM
Mohit Negi
Mohit Negi - avatar
1 Answer
+ 2
I am not sure If I understand well,but the c++ is not strict object oriented language.In c++ there is a rule you use a variable there you currently need it. It is not necessary construct an object for it which the variable belong as a member.
15th Apr 2017, 5:17 PM
Highman
Highman - avatar