[] and = operators together

Hello guys!
I wanna use [] and = operators together.
1
2
   className x();
   x[value1] = value2;

How I can do it and get two values in my class?
className x();

This is a mistake.
It does not define an object named x. It declares a function named x() that returns a className and takes no parameters.

(Resisting the strong urge to link to the FQA instead...)
http://www.parashift.com/c++-faq/empty-parens-in-object-decl.html

How I can do it and get two values in my class?

It all revolves around your operator[] that you overload for your class.
First, if value1 doesn't exist, it has to be added.
Second, return a reference to whatever value1 maps to, so that it can be assigned to.

What you are trying to achieve is very similar to the operator[] of std::map.
http://www.cplusplus.com/reference/map/map/operator%5B%5D/
Do you want to overload two operators in your class? In the code snippet, you seem to have called only one operator[]. The = operator is not your class assignment operator.
Topic archived. No new replies allowed.