[英]Calling an operator function in a class in 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??
}
你称之为myBytes();
或myBytes.operator();
如果你想详细说明它。
当然,您还需要传递函数所需的参数。 像myBytes("foo", "bar");
你可以称之为
Getbytes myBytes;
unsigned char s1[] = "Hello";
unsigned char s2[] = "World";
myBytes( s1, s2 );
或者
myBytes.operator()( s1, s2 );
如果运算符不更改 Getbytes 类的对象本身,则应将其声明为
int operator() (unsigned char* C1, unsigned char* C2) const;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.