🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by Mayan Moudgill Sun, 06 Sep 1992 18:29
Is coercion to a reference defined?
#111
Author: Mayan Moudgill
Date: Sun, 06 Sep 1992 18:29
22 lines
747 bytes
I'm trying to implement an embedded list template class.
It looks something like:

template <class T> class emList {
   ...
   emList *    _next;
   T           _value;
   ...
};

I'd like to define TWO functions:

     operator T () { return _value;}

and
     operator T& () { return _value;}

Is the second definition legal?
How would the compiler resolve them?

:)
Mayan
Re: Is coercion to a reference defined?
#117
Author: Marshall Cline
Date: Wed, 09 Sep 1992 04:58
18 lines
1306 bytes
In article <1992Sep6.182905.6603@cs.cornell.edu> moudgill@cs.cornell.edu ( Mayan Moudgill) writes:
...
>I'd like to define TWO functions:
>     operator T () { return _value;}
>and
>     operator T& () { return _value;}

They would, as stated, be ambiguous.  However, you can make the first one
a `const' member function, thereby disambiguating them based on the constness
of the object being converted to a T.

++Marshall
--
Marshall Cline
--
Marshall P. Cline, Ph.D. / Paradigm Shift, Inc / 65 N Main St/Norwood, NY 13668
cline@sun.soe.clarkson.edu / 315-353-4585 / FAX: 315-353-6100
Maintainer, C++ FAQ
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads