考慮下面的代碼:語法爲模板的成員函數
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
放在同一行上的效果相同?還是有一些細微的差別,我不知道...?
(另外,如果有人能想到更好的標題請讓我知道。)
這種同構稱爲Currying(參見http://en.wikipedia.org/wiki/Currying)。例如,它是Haskell編程語言的構建磚之一。 – 2011-01-19 07:39:16