Re: User defined conversion to builtin type gives l-value?
On Apr 11, 5:13 pm, Arne Mertz <n...@arne-mertz.de> wrote:
Hi all, following example:
template <class T, class U>
T foo(U const& u, T const& t)
{
return T temp(u) /= t;
}
gives me an error "'/=' left operand has to be an l-value" on
MSVC 2008 express, if T is a builtin type (e.g. double). In my
case, U has an konversion operator to double. If I try the
same with T being a builtin class and either providing a
konversion ctor for T or providing an konversion operator for
U, it works. My question is: is that right according to the
standard? I found a line saying that implicit standard
conversions result in l-values, but as far as i can see this
is an explicitly called user defined conversion or not?
Alf's already pointed out a couple of errors in your
formulation: illegal syntax in the example, constructors for a
build in type. Those aren't nits: copy paste the actual code
for code, and as for the others: being able to express yourself
clearly, concisely and precisely in your native language is a
prerequisite to learning any programming language. (I realize
that English probably isn't your native language, judging from
your return address, but in this case, the translation would be
literal to and from any other language: "Es gibt keinen
Constructor f=FCr eingebaut Type" in German, as well. And if you
really do have problems with English, the people in
de.comp.lang.iso-c++ are very friendly as well.)
Anyway: I don't know where you found anything saying that
implicit standard conversions result in lvalues. The only
conversions which result in lvalues are those to references, and
none of the standard conversions result in a references. The
only way something like "return T(u) /= t ;" could be legal is
if T had a user defined conversion operator which returned a
reference, or if operator/=() was a member function of T (or a
base class of T). (The latter is actually a frequent case.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34