C++ 类,范围解析操作符::,类的成员函数,类的成员变量,类的成员修饰符
#include<iostream> using namespace std; class People { public: string name; // member function declared string getName(void); void setName(string name); }; // member function defined string People::getName(void) { return name; } void People::setName(string yourName) // 不能定义成name,不能和成员变量名相同,需要另起一个形参名字 { name = yourName; } int main() { People p1; p1.setName("rui"); string yourName = p1.getName(); cout << "your name is: " << yourName << endl; return 0; }