C++之在类外定义成员函数

#include <iostream>


using namespace std;


class Student
{
public:
void get();
void display();
private:
int age;
string name;
};


void Student::get()
{
cin>>age>>name;
}


void Student::display()
{
cout<<"age:"<<age<<endl;
cout<<"name:"<<name<<endl;
}


int main()
{
Student stud;
stud.get();
stud.display();


return 0;
}

猜你喜欢

转载自blog.csdn.net/wrc_nb/article/details/80277944