我尝试使用函数调用运算符重载的模板,就像下面的程序:
#include <stdio.h>
struct Apple
{
template <typename tn> tn value ();
template <typename tn> tn operator () ();
};
template <> int Apple::value ()
{
return 10;
}
template <> int Apple::operator () ()
{
return 10;
}
int main()
{
Apple apple;
printf("Value : %d\n", apple<int>());
printf("Value : %d\n", apple.value<int>());
return 0;
}
尽管第二个打印中的值函数调用没有显示任何错误,但第一个打印中的函数调用运算符显示了“预期的主表达式”错误。我不知道我做错了什么。有人能帮我知道问题吗?提前感谢。
auto
的意义在于何处,既然它与写int
完全等效? - T.C.typename T :: some_inner_type :: some_mess
时。我只是指出OP不需要一个具有“void”参数的模板函数运算符。 - vsoftco