【发布时间】:2011-01-19 03:07:08
【问题描述】:
考虑以下代码:
template <typename Datatype>
class MyClass
{
void doStuff();
template <typename AnotherDatatype>
void doTemplateStuff(AnotherDatatype Argument);
};
template <typename Datatype>
void MyClass<Datatype>::doStuff()
{
// ...
}
template <typename Datatype>
template <typename AnotherDatatype>
void MyClass<Datatype>::doTemplateStuff(AnotherDatatype Argument)
{
// ...
}
如果我这样压缩第二个成员函数doTemplateStuff,则无法编译:
template <typename Datatype, typename AnotherDatatype>
void MyClass<Datatype>::doTemplateStuff(AnotherDatatype Argument)
{
// ...
}
这是为什么?用逗号分隔模板信息不应该与将每个 typename 放在自己的行上具有相同的效果吗?还是有一些我不知道的细微差别...?
(另外,如果有人能想到更好的标题,请告诉我。)
【问题讨论】:
标签: c++ templates class syntax