Topic: Should this be legal? implicit convertion followed by operator()
Author: scott douglass <sdouglass%_%junk@_.arm.com>
Date: 1998/12/18 Raw View
Hello,
Section 13.3.1.1.2 does not seem to allow the following:
struct X { void operator()(); };
struct Y { operator X(); };
void f(Y& y) { y(); } /* meaning 'static_cast<X>(y)()' */
Is this an oversight?
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "Bill Wade" <bill.wade@stoner.com>
Date: 1998/12/19 Raw View
scott douglass wrote in message <75dvhd$rh@sis.cambridge.arm.com>...
>
>Hello,
>
>Section 13.3.1.1.2 does not seem to allow the following:
>
> struct X { void operator()(); };
> struct Y { operator X(); };
> void f(Y& y) { y(); } /* meaning 'static_cast<X>(y)()' */
>
>Is this an oversight?
It is consistent with the way other member functions work.
struct A { void operator+(A); };
struct B { operator A(); };
struct C { friend void operator+(C,C); };
struct D { operator C(); };
void foo()
{
B b;
b+b; // This is an error. Can't do conversion and then call a member.
D d;
d+d; // This is fine. Ok to convert and then call a non-member.
}
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "Larry Brasfield" <larry_br@sea_net.com>
Date: 1998/12/19 Raw View
scott douglass wrote in message <75dvhd$rh@sis.cambridge.arm.com>...
>
>Hello,
Greetings.
>Section 13.3.1.1.2 does not seem to allow the following:
>
> struct X { void operator()(); };
> struct Y { operator X(); };
> void f(Y& y) { y(); } /* meaning 'static_cast<X>(y)()' */
>
>Is this an oversight?
Not any more than it would be for the following:
class Fib {
char factoid;
public:
Fib(char what) : factoid(~what) {}
char tell() { return factoid; }
char truth() { return ~factoid; }
};
class Billy {
char knowl_edge;
public:
void beTheMan(); // acquires value: char knowl_edge
operator Fib() { return Fib(knowl_edge); }
};
char dissemble()
{
Billy thePres;
thePres.beTheMan();
return thePres.Truth();
}
The "correct" compiler behavior here is to
insist that Billy has no Truth member. It is
not enough that somewhere in the set of
possible conversions from a Billy that such
a member can be found.
For a function call expression, it is more
accurate to think of it as a call on a specific
object rather than as a general expression
of the sort where conversions are applied.
Even though, syntactically, member access
and function call operators have operands,
they are not binary operations in the usual
sense. A language rule where an object
would be converted to allow a member
call or access to succeed would not only
be confusing; it would tend to often be
useless because the access or call would
be applied to a temporary object.
So, even though I was not present when
this nonbehavior was decided upon, I am
sure it was not an oversight.
--Larry Brasfield
Above opinions may be mine alone.
(Humans may reply at unundered larry_br@sea_net.com )
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]