Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

operator overloading problem

1 view
Skip to first unread message

Mark Williams

unread,
Dec 11, 2000, 1:31:03 PM12/11/00
to
Should the following compile (or is it ambiguous).

If not ambiguous, what should it do?

-------------------------
#include <stdio.h>

struct B {};

struct A {
operator const int &() const { printf("Called operator int!\n");
return 1; }
operator B() { B b; return b; }
};

int operator && (B b, int i)
{
printf("Called operator &&!\n");
return(0);
}

int main()
{
A a;

return a && 1;
}

-------------
Mark Williams


Sent via Deja.com http://www.deja.com/
Before you buy.

[ Send an empty e-mail to c++-...@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]

Wil Bloodworth

unread,
Dec 13, 2000, 10:23:26 AM12/13/00
to
Mark,

It will compile but produces warnings. I have modified your
example so that warnings don't exist. There's nothing
exactly "broken" syntatically but it seems useless in the
context provided though.

#include <stdio.h>
struct B {};
const int ONE = 1;


struct A {
operator const int &() const
{
printf("Called operator int!\n");

return ONE;


}
operator B() { B b; return b; }
};

int operator && (B, int)


{
printf("Called operator &&!\n");
return(0);
}

int main() {
A a;
int temp = a;
return a && temp;
}

- William Bloodworth

> Should the following compile (or is it ambiguous).
>
> If not ambiguous, what should it do?

> #include <stdio.h>
>
> struct B {};
> struct A {
> operator const int &() const { printf("Called operator int!\n");
> return 1; }
> operator B() { B b; return b; }
> };
>
> int operator && (B b, int i)
> {
> printf("Called operator &&!\n");
> return(0);
> }
>
> int main()
> {
> A a;
>
> return a && 1;
> }

[ Send an empty e-mail to c++-...@netlab.cs.rpi.edu for info ]

0 new messages