user2370139
user2370139

Reputation: 1305

About operator overloading in C++

I have a question about operators, let's say that I have a class myclass and that i have overloaded its operator *=, [], and +

Can I access them inside the member functions with this->*=, this->[], *this + * this... ?

Upvotes: 0

Views: 67

Answers (4)

Sebastian Mach
Sebastian Mach

Reputation: 39109

this is just a pointer. You can do all of the following with any pointer.

This is the preferred way as it does not loose operational syntax:

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

Its just dereferencing the pointer.

You can also use their names:

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

Upvotes: 1

0x26res
0x26res

Reputation: 13952

there's a special synthax for pointers, it looks like that:

this->oprator[](0)

this->operator+(*this)

Upvotes: 0

Jiwan
Jiwan

Reputation: 731

If you are not using external operators, it should works like that : this->operator[](args)

Upvotes: 0

Joseph Mansfield
Joseph Mansfield

Reputation: 110768

Yes, you can access them in multiple ways. You could, for example, do this:

*this + something

Or alternatively:

this->operator+(something)

Upvotes: 3

Related Questions