我试图做这样的事情。
template <typename T>
struct thingo {
int always;
T sometimes;
};
thingo <> compile_error; // <- wont compile
thingo <nullptr_t> wastes_space; // compiles but nullptr_t takes space anyway
从int包装器继承是实现此目的的唯一方法吗?
答案 0 :(得分:6)
怎么样:
struct None {};
// Or without an extra struct:
// typedef void None;
template <typename T = None>
struct thingo {
int always;
T sometimes;
};
template <>
struct thingo<None> {
int always;
};