如何在头文件中声明命名空间别名,然后在源文件中使用它? [英] How do I declare a namespace alias in a header file, then use it in a source file?
本文介绍了如何在头文件中声明命名空间别名,然后在源文件中使用它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是一个非常简化的例子,我想要做的...
头文件:
命名空间A {
命名空间B {
int getInt
}
}
命名空间AB = A :: B;
源文件:
#includeheader_file.h
#include< iostream>
int AB :: getInt(){//错误AB不是命名空间名称
return 123;
}
解决方案
在头文件中声明命名空间,或者像注释所说的那样声明这样做:
命名空间B {namespace C {}}
namespace A = B :: C;
I want to put a namespace alias (ie namespace A = B::C) in a header file so I can use it in source files, but the compiler just tells me that its "not a namespace name". Any thoughts?
This is a very simplified axample of what I'm trying to do...
header file:
namespace A{
namespace B{
int getInt();
}
}
namespace AB = A::B;
source file:
#include "header_file.h"
#include <iostream>
int AB::getInt(){ // Error "AB is not a namespace name"
return 123;
}
解决方案
You need to include the file that declares the namespace in the header file or as the comments say do this:
namespace B { namespace C { } }
namespace A = B::C;
这篇关于如何在头文件中声明命名空间别名,然后在源文件中使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文