繁体   English   中英

关于C ++中的运算符重载

[英]About operator overloading in C++

我有一个关于运算符的问题,比方说,我有一个类myclass,并且我已经重载了它的运算符* =,[]和+

我可以在成员函数中使用this-> * =,this-> [],* this + * this ...访问它们吗?

是的,您可以通过多种方式访问​​它们。 例如,您可以这样做:

*this + something

或者:

this->operator+(something)

this只是一个指针。 您可以使用任何指针执行以下所有操作。

这是首选方法,因为它不会松散操作语法:

(*this)[2]
(*this)(foo, bar)
*this / 3
*this * (that - 3) + 5

它只是取消引用指针。

您也可以使用其名称:

this->operator[](2)
this->operator() (foo, bar)
this->operator/ (3)
this->operator*(that - 3) + 5

指针有一个特殊的合奏,看起来像这样:

this->oprator[](0)

this->operator+(*this)

如果您不使用外部运算符,它应该像这样: this->operator[](args)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM