473,398 Members | 2,188 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,398 software developers and data experts.

Conversation operator as a lval?

Does C++ provide a means to use a conversion operator as a lval?

ie, I want:

class superInt
{
public:
operator int() { return this->value; }
private:
int value;
};

....to instead be this:

class superInt
{
public:
int& operator int() { return this->value; }
private:
int value;
};

....which will not compile.

I suspect the C++ language designers avoided this on purpose, but I
thought I would ask here just in case there is a means to do this (in
some other way then I present above).

Such a thing would save me time re-writing a bunch of overloaded
operators for superInt (among other things).

-Matt
--
Remove the "downwithspammers-" text to email me.
Jul 23 '05 #1
2 1493
Matt wrote:
Does C++ provide a means to use a conversion operator as a lval?\
Sure.
ie, I want:

class superInt
{
public:
operator int() { return this->value; }
Should probably be

operator int() const { return this->value; }
private:
int value;
};

...to instead be this:

class superInt
{
public:
int& operator int() { return this->value; }
operator int&() { return this->value; }
private:
int value;
};

...which will not compile.
Of course.

I suspect the C++ language designers avoided this on purpose,
No, they didn't.
but I
thought I would ask here just in case there is a means to do this (in
some other way then I present above).
Very good choice.
Such a thing would save me time re-writing a bunch of overloaded
operators for superInt (among other things).


But it is rather dangerous. Be careful.

Victor
Jul 23 '05 #2
On Mon, 31 Jan 2005 12:01:17 -0500, Victor Bazarov
<v.********@comAcast.net> wrote:

operator int&() { return this->value; }
Great, I'm glad I asked here. Thanks!
Such a thing would save me time re-writing a bunch of overloaded
operators for superInt (among other things).


But it is rather dangerous. Be careful.


Yes, I can see where it can be quite dangerous. I think I will avoid
it whenever I can...especially since I've already written all my
overloaded operators for the task at hand.

-Matt
--
Remove the "downwithspammers-" text to email me.
Jul 23 '05 #3

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

Similar topics

2
by: quadric | last post by:
Hi, I have an application that requires that Python initiate and mediate a live and iterative conversation between an external application (in which Python is embedded) and an external Excel...
3
by: owais | last post by:
I have one vb6 application in which it uses one variable Private m_wndprcNext and uses in SetWindowLong hWndCur, GWL_WNDPROC, m_wndprcNex one other calling of method is in same clas
3
by: MS News | last post by:
hi I need help.I want to to record my Skype Messenger Conversation i.e Incoming and Outgoing conversation in C#.Please if some body know guide me.I need starting help.what should i study for...
1
by: miaohua1982 | last post by:
the code is as follows: #include<iostream> using namespace std; template<class T> class Myauto_ptr { public: Myauto_ptr(T*ptr=0):_Myptr(ptr){}
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.