C++中写class时,对私有变量通常使用set和get方法来进行访问,比较标准的例子
class A { int ia {}; int ib {}; int ic {}; public: A (int a, int b, int c) : ia(a), ib(b), ic(c) {} //构造函数 void seta(int a) { ia = a; } void setb(int b) { ib = b; } void setc(int c) { ic = c; } int geta() const { return ia; } int getb() const { return ib; } int getc() const { return ic; } };
标签:const,私有,C++,int,ia,ic,ib,class From: https://www.cnblogs.com/wphl-27/p/16932255.html