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?
2 Respuestas
+ 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.
+ 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.