为什么命名空间不能是模板参数? [英] Why can't namespaces be template parameters?
本文介绍了为什么命名空间不能是模板参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道名称空间不能是模板参数。请参阅问题专门用于命名空间的模板:
I understand that namespaces cannot be template parameters. See the question, "template specialized on a namespace":
给定:
Given:
namespace A {
class Foo;
class Bar;
}
namespace B {
class Foo;
class Bar;
}
我想模板命名空间上的类 A
或 B
,使得以下工作:
I want to template a class on the namespace A
or B
such that the following works:
template<name> class C {
name::Foo* foo;
name::Bar* bar;
};
我想知道为什么会出现这种情况。我理解模板不是结构,但是对编译器的设计有技术限制吗?
I was wondering why this is the case. I understand that templates aren't structures, but is there a technical limitation to the compiler's design? Or is there some significant trade off for implementing this functionality?
推荐答案
这将是:
- (IMO)不适当:命名空间避免名称冲突。
- 不必要的:它将实现无法用struct完成的任何事情。
- 可能很困难:命名空间isn是一个完整的,独立的实体。命名空间的不同成员可以在不同的标头,甚至不同的编译单元中声明。
这篇关于为什么命名空间不能是模板参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文