/*
* C++中的命名空间
* OS: ubuntu
* Complier: g++
*/
#include <iostream>
using namespace std;
namespace Beijing
{
class Examinee
{
public:
Examinee(float score)
{
this->score = score;
}
bool GoToPeking();
void Result();
private:
float score;
};
bool Examinee::GoToPeking()
{
return ((this->score) > 550);
}
void Examinee::Result()
{
if (GoToPeking())
cout << "Successfully" << endl;
else
cout << "Failed" << endl;
}
}
namespace JiLin
{
class Examinee
{
public:
Examinee(float score)
{
this->score = score;
}
bool GoToPeking();
void Result();
private:
float score;
};
bool Examinee::GoToPeking()
{
return ((this->score) > (550 + 100));
}
void Examinee::Result()
{
if (GoToPeking())
cout << "Successfully" << endl;
else
cout << "Failed" << endl;
}
}
using namespace Beijing; // Set default namespace
int main(void)
{
Examinee examinee_a(600); // The class has the default namespace (Beijing)
examinee_a.Result();
JiLin::Examinee examinee_b(600); // Specify a namespace for the class
examinee_b.Result();
return 0;
}
* C++中的命名空间
* OS: ubuntu
* Complier: g++
*/
#include <iostream>
using namespace std;
namespace Beijing
{
class Examinee
{
public:
Examinee(float score)
{
this->score = score;
}
bool GoToPeking();
void Result();
private:
float score;
};
bool Examinee::GoToPeking()
{
return ((this->score) > 550);
}
void Examinee::Result()
{
if (GoToPeking())
cout << "Successfully" << endl;
else
cout << "Failed" << endl;
}
}
namespace JiLin
{
class Examinee
{
public:
Examinee(float score)
{
this->score = score;
}
bool GoToPeking();
void Result();
private:
float score;
};
bool Examinee::GoToPeking()
{
return ((this->score) > (550 + 100));
}
void Examinee::Result()
{
if (GoToPeking())
cout << "Successfully" << endl;
else
cout << "Failed" << endl;
}
}
using namespace Beijing; // Set default namespace
int main(void)
{
Examinee examinee_a(600); // The class has the default namespace (Beijing)
examinee_a.Result();
JiLin::Examinee examinee_b(600); // Specify a namespace for the class
examinee_b.Result();
return 0;
}
转载于:https://blog.51cto.com/programs/245984