【发布时间】:2019-04-26 05:37:22
【问题描述】:
假设我有以下模板类:
template<typename T>
class Foo {
struct store_t {
uint8_t data[];
} store;
/// other stuff using T
}
有没有办法构造一个专门的内部结构版本,相当于这样的东西:
class Foo {
struct store_t {
uint16_t f1;
uint16_t f2;
} store;
/// other stuff using T
}
我宁愿保持大多数“使用 T 的其他东西”不专业。不过,我会专门研究一些访问器。 我觉得我想写一些类似的东西
template<>
struct store_t {
uint16_t f1;
uint16_t f2;
} Foo<someT>::store;
但这当然行不通。
【问题讨论】:
-
对内部结构类型使用另一个模板参数,即
template <typename T, typename TInternal> class Foo。
标签: c++ templates template-specialization