namespace (一)

2014-11-24 07:35:59 · 作者: · 浏览: 0
1 person.h
[cpp]
#ifndef PERSON_H
#define PERSON_H
#include
#include
using namespace std;
namespace stdperson
{
class Person
{
public:
Person();
Person(string name, int age);
void SetName(string name);
void SetAge(int age);
string GetName();
int GetAge();
private:
string name;
int age;
};
}
#endif PERSON_H
#ifndef PERSON_H
#define PERSON_H
#include
#include
using namespace std;
namespace stdperson
{
class Person
{
public:
Person();
Person(string name, int age);
void SetName(string name);
void SetAge(int age);
string GetName();
int GetAge();
private:
string name;
int age;
};
}
#endif PERSON_H
2 person.cpp
[cpp]
#include"person.h"
using namespace stdperson;
Person::Person()
{
SetName("默认值");
SetAge(0);
}
//--------------------------------------------------------------------------
Person::Person(string name, int age)
{
SetName(name);
SetAge(age);
}
//---------------------------------------------------------------------------
void Person::SetName(string name)
{
this->name = name;
}
//---------------------------------------------------------------------------
void Person::SetAge(int age)
{
this->age = age;
}
//---------------------------------------------------------------------------
string Person::GetName()
{
return this->name;
}
//---------------------------------------------------------------------------
int Person::GetAge()
{
return this->age;
}
//----------------------------------------------------------------------------
#include"person.h"
using namespace stdperson;
Person::Person()
{
SetName("默认值");
SetAge(0);
}
//--------------------------------------------------------------------------
Person::Person(string name, int age)
{
SetName(name);
SetAge(age);
}
//---------------------------------------------------------------------------
void Person::SetName(string name)
{
this->name = name;
}
//---------------------------------------------------------------------------
void Person::SetAge(int age)
{
this->age = age;
}
//---------------------------------------------------------------------------
string Person::GetName()
{
return this->name;
}
//---------------------------------------------------------------------------
int Person::GetAge()
{
return this->age;
}
//----------------------------------------------------------------------------
3 student.h
[cpp]
#ifndef STUDENT_H
#define STUDENT_H
#include "person.h"
using namespace stdperson;
namespace stdstudent
{
class Student : public Person
{
public:
Student(string name, int age, string schoolName);
Student();
string GetSchoolName();
void SetSchoolName(string schoolName);
private