函子调用(其他字符)
|
我试图建立一个最小的例子:
struct Functor
{
void operator()(int& a)
{
a += 1;
}
void other(int& a)
{
a += 2;
}
};
template <typename foo>
class Class
{
public:
void function()
{
int a = 10;
foo()(a);
std::cout << a << std::endl;
}
};
int main()
{
Class<Functor> c;
c.function();
}
我的问题是:为什么甚至可以在没有对象的情况下调用纯类型的运算符?如何像调用operator()
一样调用函数other
?
没有找到相关结果
已邀请:
3 个回复
磨标烫徽啪
氮顺
创建一个类型为
的临时对象(这是
部分),然后以object11ѭ作为参数在该对象上调用
((12ѭ部分)。
耐扫鹤胶鞭