namespace (二)

2014-11-24 07:35:59 · 作者: · 浏览: 1
:
string schoolName;
};
}
#endif
#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:
string schoolName;
};
}
#endif
4 student.cpp
[cpp]
#include "student.h"
using namespace stdstudent;
Student::Student(string name, int age, string schoolName)
:Person(name, age),schoolName(schoolName)
{
}
//---------------------------------------------------------------
Student::Student()
:Person()
{
}
//----------------------------------------------------------------
void Student::SetSchoolName(string schoolName)
{
this->schoolName = schoolName;
}
//----------------------------------------------------------------
string Student::GetSchoolName()
{
return this->schoolName;
}
#include "student.h"
using namespace stdstudent;
Student::Student(string name, int age, string schoolName)
:Person(name, age),schoolName(schoolName)
{
}
//---------------------------------------------------------------
Student::Student()
:Person()
{
}
//----------------------------------------------------------------
void Student::SetSchoolName(string schoolName)
{
this->schoolName = schoolName;
}
//----------------------------------------------------------------
string Student::GetSchoolName()
{
return this->schoolName;
}
5 main.cpp
[cpp]
#include"person.h"
#include"student.h"
using namespace stdperson;
using namespace stdstudent;
int main()
{
Person p("张三", 22);
Student s("里斯", 23, "香港大学");
cout<
cout<
cout<<"**************************************************"<
cout<
cout<
cout<
system("pause");
return 0;
}
#include"person.h"
#include"student.h"
using namespace stdperson;
using namespace stdstudent;
int main()
{
Person p("张三", 22);
Student s("里斯", 23, "香港大学");
cout<
cout<
cout<<"**************************************************"<
cout<
cout<
cout<
system("pause");
return 0;
}
6运行结果
例2
1 read.h
[cpp]
#ifndef READ_H
#define READ_H
#include
#include
#include
using namespace std;
namespace stdread
{
void ReadToger(ifstream& ifs, string word);
void SayHello();
}
#endif
#ifndef READ_H
#define READ_H
#include
#include
#include
using namespace std;
namespace stdread
{
void ReadToger(ifstream& ifs, string word);
void SayHello();
}
#endif
2 read.cpp
[cpp]
#include "read.h"
using namespace stdread;
void stdread::ReadToger(ifstream& ifs, string word)
{
while(ifs>>word)
{
cout<
}
}
void stdread::SayHello()
{
cout<<"hello, welcome to here!"<
}
#include "read.h"
using namespace stdread;
void stdread::ReadToger(ifstream& ifs, string word)