使用命名空间解决名字冲突
2017-03-15 22:37
441 查看
//main()函数
//header1.h文件
//hearder2.h头文件
**#include <iostream> #include <fstream> #include <cstring> #include <strstream> #include "header1.h.h" #include "hearder2.h.h" using namespace std; int main() { ns1::Student stud1(101,"Wang",18); stud1.get_data(); cout<<ns1::fun(5,3)<<endl; ns2::Student stud2(102,"Li",'f'); stud2.get_data(); cout<<ns2::fun(5,3)<<endl; } **
//header1.h文件
**// // Created by andrew on 15/03/17. // #ifndef UNTITLED9_HEADER1_H_H #define UNTITLED9_HEADER1_H_H #include <string> #include <cmath> #include <iostream> using namespace std; namespace ns1 { class Student { public: Student(int n,string nam,int a) {num=n; name=nam; age=a; } void get_data(); private: int num; string name; int age; }; void Student::get_data() { cout<<num<<" "<<name<<" "<<age<<endl; } double fun(double a,double b) {return sqrt(a+b);} } #endif //UNTITLED9_HEADER1_H_H **
//hearder2.h头文件
**// // Created by andrew on 15/03/17. // #ifndef UNTITLED9_HEARDER2_H_H #define UNTITLED9_HEARDER2_H_H #include <string> #include <cmath> #include <iostream> using namespace std; namespace ns2 { class Student { public: Student(int n, string nam, char s) { num = n; name = nam; sex = s; } void get_data(); private: int num; string name; char sex; }; void Student::get_data() { cout << num << " " << name << " " << sex << endl; } double fun(double a, double b) { return sqrt(a-b); } } #endif //UNTITLED9_HEARDER2_H_H **
相关文章推荐
- 使用命名空间解决名字冲突
- 使用命名空间解决名字冲突
- dom4j中使用xpath解析带命名空间的xml文件,取不到节点的解决办法
- 解决<fx:Style>样式设置中报错 必须使用命名空间限定 CSS 选择器“Alert”中的类型“Alert”
- error C2872: “flann”: 不明确的符号 --- PCL 与OpenCV2 的flann命名空间冲突问题的解决方法
- 关于使用Compare类时:“未能找到类型或命名空间“Compare”,命名空间compare”的解决
- 解决MVC使用时Views必须引用完整的命名空间才得到对象的问题
- 如何解决“xxxxxx是“命名空间”,但此处被当做“类型”来使用”的问题
- 解决ambiguous symbol命名空间中类名、变量名冲突的问题
- PHP使用Memcache时模拟命名空间及缓存失效问题的解决
- 运用名字空间解决数据库冲突问题
- 解决办法:Flex4使用Efflex_v0.03.swc (Fx4/FP10),在该命名空间中多次定义了组件 MotionPath……
- 调用opencv时,使用Egien工具出现“error C2061: 语法错误: 标识符“Matrix””和“error C2653: “Eigen”:不是类或命名空间名称”该如何解决?
- TGridDrawState名字空间冲突问题及解决方法(E2015 Ambiguity between 'TGridDrawState' and 'Gridseh::TGridDrawState')
- Javascript 命名空间解决命名冲突问题
- jQuery中$符号的使用及解决命名冲突
- TGridDrawState名字空间冲突问题及解决方法
- spring中使用mvc和tx命名空间的冲突
- 名字空间解决数据库冲突问题
- PHP使用Memcache时模拟命名空间及缓存失效问题的解决