在C++; 学习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?? }
您将其称为在C++; 学习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?? },c++,function,class,operator-keyword,C++,Function,Class,Operator Keyword,您将其称为myBytes()或myBytes.operator()如果你想详细说明的话 当然,您还需要传递函数所需的参数。像myBytes(“foo”,“bar”)你可以这样称呼它 Getbytes myBytes; unsigned char s1[] = "Hello"; unsigned char s2[] = "World"; myBytes( s1, s2 ); 或 如果操作符没有更改Getbytes类的对象本身,那么应该声明如下 int operator() (unsigned
myBytes()
或myBytes.operator()代码>如果你想详细说明的话
当然,您还需要传递函数所需的参数。像myBytes(“foo”,“bar”)代码>你可以这样称呼它
Getbytes myBytes;
unsigned char s1[] = "Hello";
unsigned char s2[] = "World";
myBytes( s1, s2 );
或
如果操作符没有更改Getbytes类的对象本身,那么应该声明如下
int operator() (unsigned char* C1, unsigned char* C2) const;
函数调用操作符使对象可以作为函数调用,因此您只需像任何其他函数一样“调用”对象。您的main
缺少返回类型main
必须用返回类型声明,并且返回类型必须是int
。在类定义的结尾}
之后,您还缺少一个分号。另一方面,分号不属于函数定义之后。因此,关闭操作符()
重载的}
后的code>不属于那里。
int operator() (unsigned char* C1, unsigned char* C2) const;