Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Static" class member

Tags:

c++

For example, x is static in class's definition. I should use x in this way:

class_name::x; rather than instance_of_class.x;

My question is, is the latter one also legal? Or just not correct?

Thanks.

like image 690
Anders Lind Avatar asked Feb 09 '12 21:02

Anders Lind


1 Answers

It is legal and correct, but the general consensus is to use the scope resolution operator.

class_name::x

rather than

instance.x
like image 191
Luchian Grigore Avatar answered Oct 07 '22 15:10

Luchian Grigore