c++ - 为什么命名空间不能是模板参数?

标签 c++ templates namespaces language-design

我了解命名空间不能是模板参数。见问题,"template specialized on a namespace" :

Given:

namespace A {
  class Foo;
  class Bar;
}

namespace B {
  class Foo;
  class Bar;
}

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;
};

我想知道为什么会这样。我知道模板不是结构,但编译器的设计是否存在技术限制?还是在实现此功能时需要做出重大权衡?

最佳答案

当 Bjarne Stroustrup 在 C++ 标准 session 上第一次开始谈论模板时,他提到命名空间作为模板参数。 react 持怀疑态度,部分原因是命名空间本身太新了,我们害怕将两个我们不理解的东西结合起来。

关于c++ - 为什么命名空间不能是模板参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12905951/

相关文章:

c++ - 如何使用 Qt 在代码中访问提升的小部件的 UI 元素?

templates - Laravel Blade 模板,URL::to 中的 foreach 变量?

c++ - 使模板接受特定的类/类族?

c++ - 如何告诉 Borland C++ 枚举在类中?

cocoa - NSXMLDocument,带有命名空间的nodesForXPath

c++ - OpenCV 在鼠标移动时停止渲染

c++ - 使用鼠标滚轮缩放 QChartView 的 x 轴

c++ - 绝对整数值比较和平方值比较。是等价的吗?

c++ - 使用模板在 C++ 中实现堆栈

python - 将类的内部命名空间作为字典返回