在 C++ 中调用类中的运算符函数
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;
相关文章:
- 为什么将值返回函数传递给重载=运算符对运算符函数有效,而对其他运算符无效
- 在 C++ 中调用类中的运算符函数
- 错误 C2676:std::set::const_iterator 没有运算符 + 函数?
- 为什么 ADL 的运算符函数行为与其他函数不同?
- 将内置类型变量传递给只有一个类类型参数的"+"运算符函数时自动类型转换的构造函数
- 第二个常量在运算符函数中做什么?
- 重载赋值运算符函数和复制构造函数中的错误
- 内置类型的运算符函数
- 如何调用运算符函数添加两个对象?
- Const 仍然允许在运算符函数 c++ 下进行更改
- 在呼叫运算符函数const中调用运算符时错误
- 是否有一种方法可以在超载运算符函数中接触默认运算符函数
- 重载时获取堆栈溢出 >> 运算符函数是为类调用的。我需要进行哪些更改?
- 运算符 [] 函数的实现是如何工作的
- C++:使用父类运算符函数更新子类对象的继承变量
- 创建一个接受 2 个输入参数的文本运算符函数
- 为什么找不到重载运算符函数?
- 为什么auto_ptr中有模板复制构造函数和覆盖运算符函数
- 为什么某些C++标准库“运算符<<”函数将其流宽度重置为 0
- C++SFINAE运算符/函数结果类型检查