Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Non-static function modify a static variable in c++

Tags:

c++

can Non-static function modify a static variable in c++

like image 406
Josh Morrison Avatar asked Feb 25 '11 19:02

Josh Morrison


2 Answers

Yes, a non-static member function can modify a static data member as long as the data member's visibility allows it.

like image 175
Ferruccio Avatar answered Oct 08 '22 09:10

Ferruccio


Yes, see this example for a small sample program.

Conversely a static function cannot modify a regular member variable the way a regular member function can.

like image 31
justkt Avatar answered Oct 08 '22 11:10

justkt