c++ - 我可以为并非所有非类型参数部分指定模板吗

标签 c++ templates partial-specialization

template<int, int> 
struct T;

template<> 
struct T<?, ?> {};

我想让它工作

typedef T<1, 0> t;

这会导致编译时错误

typedef T<1, 2> t;

编辑,我的意思是我希望第二个参数为 0。我不能使用 C++11 功能。

最佳答案

你的问题不是很清楚。你在找这个吗?

template <int, int>
struct T;

template<int x>
struct T<x, 0>
{
  // Definition of the struct for the allowed case
};

关于c++ - 我可以为并非所有非类型参数部分指定模板吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17830989/

相关文章:

c++ - 我的程序出现 SIGSEGV 故障

c++ - std::is_function 是如何实现的?

c++ - 有没有一种方法总是比主模板更喜欢部分特化?

c++ - 16 bpp 到 32 bpp 的转换

c++ - MyClass(expr) 之间的范围差异;和 MyClass myObject(expr);

c++ - xcode 的 c++ 项目的可执行产品

C++ 模板元编程 : constexpr function

java - Velocity #foreach 与 XmlTool 节点列表与文本节点

c++ - 如何在 C++ 中的类体之外定义一个专门的类方法?

C++ 模板特化 <int&> 不获取 int