类的成员函数

5、小作业:

类的声明和实现
大家自己课后用VS2013练习如何添加类吧

#pragma once
#include <iostream>
#include <string>
using namespace std;
class CStudent
{
    string name;
    int age;
public:
    void set_infor(string x,int y);
};
#include "CStudent.h"
void CStudent::set_infor(string x,int y)
{
    name = x;
    age = y;
    cout << name << endl;
    cout << age << endl;
}
#include "CStudent.h"
int main()
{
    CStudent zhangsan;
    zhangsan.set_infor("张三",50);
    return 0;
}

 

posted on 2021-01-05 22:41  SakuraQAQ  阅读(73)  评论(0)    收藏  举报

导航