473,378 Members | 1,393 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Left/right side of assignment

I try to write class with overloaded operator [] but class must know is
operator [] used for read or write. I simple write operator [] that
returns Dummy class that have overloaded = and overloaded conversion, so i
can find if operator [] is used for writing or reading. Is any chance to
implement this with another way?

Thanks,
Zaharije Pasalic

Jul 22 '05 #1
7 1457
hari4063 wrote:
I try to write class with overloaded operator [] but class must know is
operator [] used for read or write.
Why?
I simple write operator [] that
returns Dummy class that have overloaded = and overloaded conversion, so i
can find if operator [] is used for writing or reading. Is any chance to
implement this with another way?


What you're proposing should work fine. Strange requirement, though.

Victor
Jul 22 '05 #2
I write simple map-like (like STL) class. If i write something like:

a = map["abc"]

i wanna to read value assigned to "abc". But when i write

map["abc"] = a;

i wanna to add new value "a" to map?

Jul 22 '05 #3
hari4063 wrote:
I write simple map-like (like STL) class. If i write something like:

a = map["abc"]

i wanna to read value assigned to "abc".
What if the 'map' doesn't have a value with "abc" key?
But when i write

map["abc"] = a;

i wanna to add new value "a" to map?


OK, I understand. The apparent difference between your "map" and
the standard template map is that std::map will insert a new entry
into the storage when you use operator[].

V
Jul 22 '05 #4
hari4063 wrote:
I try to write class with overloaded operator [] but class must know is
operator [] used for read or write. I simple write operator [] that
returns Dummy class that have overloaded = and overloaded conversion, so i
can find if operator [] is used for writing or reading. Is any chance to
implement this with another way?


You can additionally write an operator [ ] const that returns directly the
value.

--
Salu2
Jul 22 '05 #5
YAP! Ok, this question is not so important, but i like to find another ways
(mostly complicated) to write something in C++ :). Whatever, thanks a lot!

Best,
Zaharije Pasalic

Jul 22 '05 #6
>>I try to write class with overloaded operator [] but class must know is
operator [] used for >>read or write.
Why?
I simple write operator [] that returns Dummy class that have overloaded =

and overloaded >>conversion, so i can find if operator [] is used for writing
or reading.
Strange requirement, though.


Scott Meyers in "More Effective C++" had an example of a copy-on-write
reference counted string class. When implementing operator[] he needed to know
if it was for a read or a write given that no special action need be taken for
a read but special action need be taken for a write.

Bjarne Stroustrup also used this technique in either D&E or TCPPPL. I just
spent a few minutes trying to find exactly which one and where but was unable
to find it.


Jul 22 '05 #7
Julián Albo wrote:
hari4063 wrote:

I try to write class with overloaded operator [] but class must know is
operator [] used for read or write. I simple write operator [] that
returns Dummy class that have overloaded = and overloaded conversion, so i
can find if operator [] is used for writing or reading. Is any chance to
implement this with another way?

You can additionally write an operator [ ] const that returns directly the
value.

Which will do nothing for him. That operator will be invoked only if
the object is const.
Jul 22 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Alex | last post by:
Hi Everone, I need some advice on how to setup 4 columns where the outside two are absolute (120px) and the inner two (side by side) are relevent (Fluid) and change with the screen. Here's my...
6
by: Suresh Jeevanandam | last post by:
Dear all, I read in "Python in a Nutshell" that when we have multiple assignments made on a single line, it is equivalent to have those many simple assignments and that the right side is evaluated...
56
by: Christian Christmann | last post by:
Hi, in the header of my class I've a constant static const int a = ( 1 << 32 ) - 1; When compiling the code, g++ issues the warning "warning: left shift count >= width of type" Why? And...
5
by: singhm | last post by:
Anybody know how to fix this?????????? ERROR: 1>c:\cs 140\assignment 5\assignment 5\main.cpp(88) : fatal error C1075: end of file found before the left brace '{' at 'c:\cs 140\assignment...
4
by: moondaddy | last post by:
I have a wpf project where I use a canvas to drag shapes around. when I drag a shape beyond the right or bottom side I get scrollbars which is good. I also get scrollbars when I zoom in and a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.