c++ - Why this class doesn't make error? -
#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
Post a Comment