我正在尝试做这样的事情。
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 包装器继承是实现此目的的唯一方法吗?
最佳答案
关于:
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;
};
关于c++ - C++ 模板参数可以为空吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26980016/