【发布时间】:2020-05-12 01:37:48
【问题描述】:
学习C++,在一个类中得到一个操作符函数却不知道怎么调用:
class Getbytes
{
public:
Getbytes();
int operator() (unsigned char* C1, unsigned char* C2)
{do something to C1 and C2 and return int; };
}
main ()
{
Getbyes myBytes;
//Here, how to call the "operator() (unsigned char* C1, unsigned char*C2)"?
myBytes??
}
【问题讨论】:
-
函数调用运算符使对象可作为函数调用,因此您只需像任何其他函数一样“调用”该对象。
-
您的
main缺少返回类型。main必须用返回类型声明,返回类型必须是int。在类定义的结束}之后,您还缺少一个分号。另一方面,分号不属于函数定义之后。所以operator()重载的关闭}之后的;不属于那里。
标签: c++ function class operator-keyword