Topic: Is coercion to a reference defined?
Author: moudgill@cs.cornell.edu ( Mayan Moudgill)
Date: Sun, 6 Sep 1992 18:29:05 GMT Raw View
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
Author: cline@sun.soe.clarkson.edu (Marshall Cline)
Date: Wed, 9 Sep 1992 04:58:00 GMT Raw View
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