头文件
#ifndef PERSON_H_
#define PERSON_H_
#include<iostream>
#include<string>
using namespace std;
class Person{
private:
// static const int LIMIT = 25;//vc++6.0太旧了,无法支撑这个操作,在新一点的版本上是可以的
enum{LIMIT=12};
string lname;
char fname[LIMIT];
public:
Person(){lname="";fname[0]='\0';}
Person(const string &ln,const char *fn="Heyyou");
// Person(const string &ln,const char *fn);
void Show() const;
void FormalShow() const;//const常成员函数,不能修改类成员数据
};
#endif
#include<iostream>
#include<string>
//#include<>
#include "person.h"
using namespace std;
Person::Person(const string &ln,const char *fn)
{
lname=ln;
strcpy(fname,fn);
}
void Person::Show() const
{
cout<<fname<<" "<<lname;
}
void Person::FormalShow() const
{
cout<<lname<<" "<<fname;
}
#include<iostream>
#include "person.h"
using namespace std;
void main()
{
Person one;
Person two("Smythecraft");
Person three("Dimwiddy","Sam");
one.Show();
cout<<endl;
one.FormalShow();
cout<<endl;
two.Show();
cout<<endl;
two.FormalShow();
cout<<endl;
three.Show();
cout<<endl;
three.FormalShow();
cout<<endl;
}