【发布时间】:2011-07-18 14:10:07
【问题描述】:
通过查看以下代码,我对第 3 行感到困惑。
第 3 行不是基本模板的特例,它更像是“类重载”。但是可以编译成功。
第7行的obj1是按照第3行定义的,但是编译失败。
怎么会?
template<typename S,int T, void(* U)()> class Bar{}; // Base template
template<int T, void(* U)()> class Bar<double, T, U>{}; // Specialization, which is good
template<int T, void(* U)()> class Bar<double, U, T>{}; // Also good, how come?
void func(){};
int main(){
//Bar<double, func, 1> obj1; // Error, from line 3
}
【问题讨论】:
标签: c++ templates specialization template-specialization