c++ - Why this class doesn't make error? -


enter image description here

#include <iostream> using namespace std;  class item{ private:     int cnt;  public:     item(){}      void func(item a){         a.cnt = 10;     } };  int main(){     return 0; } 

i assume red line make error. because 'a.cnt' value private value. learned private value must modified inner of class.

void func(a a){     a.cnt = 10; //valid } 

notice function inside class, becomes member , class member functions have access private members.

note being modified inner of class item using member function,which valid


Comments

Popular posts from this blog

How to show in django cms breadcrumbs full path? -

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -