你没有整个工程的代码,只有这么一小段,我不知道你要实现什么,所以给你下面这段代码,供你参考:
程序代码:
#include <iostream>
#include <string>
using namespace std;
class Teacher
{
public:
string name;
string sex;
public:
Teacher(string name,string sex):name(name),sex(sex){}
const string& getName()
{
return name;
}
const string& getSex()
{
return sex;
}
void show()
{
cout<<"The teacher is :"<<name<<" and his sex is:"<<sex<<" !"<<endl;
}
};
#include "stdafx.h"
#include "stdlib.h"
#include "Teacher.h"
int _tmain(int argc, _TCHAR* argv[])
{
Teacher teacher("王老师","00125425");
teacher.getName();
teacher.getSex();
teacher.show();
system("pause");
return 0;
}
最后打印结果如下:
图片附件: 游客没有浏览图片的权限,请
登录 或
注册
[此贴子已经被作者于2016-10-17 11:39编辑过]