定义成员函数

#include<iostream>
using namespace std;
class Student
{
	private:
		int num;
		char name[20];
		char sex;
	public:
		void display();
};
int main()
{
	cout<<"在类外面定义成员函数"<<endl;
	return 0;
}
void Student::display()//定义函数需要用到::(作用域限定符) 
{
	cout<<"num:"<<num<<endl;
	cout<<"name:"<<name<<endl;
	cout<<"sex:"<<sex<<endl;
}

猜你喜欢

转载自blog.csdn.net/qq_41404557/article/details/84799655
今日推荐