Re: return type of conversion opeator
"George" <George@discussions.microsoft.com> wrote in message
news:462380F6-CA4C-477E-B249-C88B506526FC@microsoft.com
Of course, G itself could be a reference,
that is, G could be H& for some H.
Do you mean typedef H& G;?
No, I mean that in operator G(), "G" doesn't have to be just an
identifier. You could have, for example,
operator const Outer::Inner * volatile & ();
But yes, this would work, too:
class H;
typedef H& G;
class C {
operator G();
// Could be written directly, without typedef, as
// operator H&();
};
In my case, G is always a class type. I think I need to define two
conversion operators, one returns a temporary object and the other one
returns a reference?
operator G();
operator G&();
Right?
If you define both, you'll have ambiguities galore. It would be very
difficult for the compiler to figure out which to use where, since in
most situations either would be equally good. Every time the compiler
can't decide, it will report an error.
What makes you think you need both? What exactly are you trying to
achieve?
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925