0

How to use overloaded array selection operator in method?

I have a class with array selection operator overloaded, I want to print the thing that is returned by ASO in method like that, class myClass { // something here public: // something and overloaded ASO here print() { for (int i=0; i<8; i++) cout<< (*this)[i] << endl; } }; I tried something like that and it didn't work, is there such thing, do I have to do it with a function outside class?

22nd May 2020, 4:55 PM
Mustafa K.
Mustafa K. - avatar
2 odpowiedzi
+ 1
So you mean something like this? https://code.sololearn.com/ch9LrW1xiV4a/?ref=app Although perhaps using whatever the overloaded operator is referring to might be easier, it should work. If your code fails, there has to be an error somewhere, so maybe you can link the code here so that we can have a look.
22nd May 2020, 5:11 PM
Shadow
Shadow - avatar
+ 1
Shadow, Thanks for the reply. I just saw that when I call the function I mistakenly had written prìnt() instead of print(), in the error message it was saying stray \303, stray \254 something like these, and I thought it was because that (*this)[i] was invalid.
22nd May 2020, 6:10 PM
Mustafa K.
Mustafa K. - avatar