专用于命名空间的模板 [英] template specialized on a namespace
本文介绍了专用于命名空间的模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给定:
命名空间A {
class Foo;
class Bar;
}
命名空间B {
class Foo;
class Bar;
}
我想在命名空间A或B上模板一个类, works:
模板< name> class C {
name :: Foo * foo;
name :: Bar * bar;
}
这可以直接完成,或者我需要创建一对struct类型
解决方案
不能在命名空间上使用模板。如果你能够使用一个类(最可能的公共属性/静态方法),你可以在类上的模板作为一个半解决方法。
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;
}
Can this be done directly or do I need to create a pair of struct types with typedefs in them?
解决方案
You can't template on a namespace. If you're able to use a class (with most likely public attributes/static methods) then you can template on the class as a semi-workaround.
这篇关于专用于命名空间的模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文