Overloading operator[]; Need Some Light

Started by
10 comments, last by Mr. LightShiner 24 years, 5 months ago
I have a problem that I can't figure out and I'm in the dark. Can someone please shine some light in my direction. I want to overload the subscript operator [], but I need to call different functions depending on what side of an assignment operator = it is on. Example:

x = foo; // call func1(i);<P>foo = x; // call func2(i,x);<P>Mr. LightShiner

Advertisement
One thing to watch out for when overloading multiple operators and using them together:

C++ keeps the original order of operations for overloaded operators. This can be a really cool thing if you're overloading to, say, enhance the functionality of a data type (a situation in which one of my teammates used operator overloading to allow ranges of data to be compared during computation comes to mind) but if you weren't aware of it, you can get some bizarre things happening depending on how you set up your operators.

-fel
~ When in doubt, add ()'s. ~

~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~

This topic is closed to new replies.

Advertisement