大佬教程收集整理的这篇文章主要介绍了C命名空间成员访问不同的文件如何? “namespace std”如何实现?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
// namespace with identifier namespace N1 { int b = 80; }
sample1.cpp使用上面的命名空间声明
#include <iostream> #include "sample.h" using namespace std; using namespace N1; int main(void) { cout << "b (in main) = " << b << endl; foo(); //written in sample2.cpp return 0; }
sample2.cpp还使用sample.h中声明的命名空间
#include <iostream> #include "sample.h" using namespace std; using namespace N1; void foo(void) { cout << "b = " << b << endl; }
当我编译时,我得到了以下错误
$> g++ sample1.cpp sample2.cpp /tmp/ccB25lEF.o:(.data+0x0): multiple deFinition of `N1::b' /tmp/cchLecEj.o:(.data+0x0): first defined here
以上是大佬教程为你收集整理的C命名空间成员访问不同的文件如何? “namespace std”如何实现?全部内容,希望文章能够帮你解决C命名空间成员访问不同的文件如何? “namespace std”如何实现?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。