Why is this ambiguous?

T

Tim H

I understand why this is ambiguous, technically, but it seems,
frankly, retarded to consider 0 as ambiguous but 1 as not, just
because 0 == NULL.

Is there any way to defeat this that does not involve changing all
code that uses 0 as an argument to use bignum(0)?


#include <string>
using namespace std;

class bignum
{
public:
bignum(int val) {}#include <string>
using namespace std;

class bignum
{
public:
bignum(int val) {}
};

int
foo(bignum arg)
{
return 0;
}
int
foo(const string &arg)
{
return 0;
}

int
main()
{
foo("hello");
foo(1);
foo(0);

return 0;
}

};

int
foo(bignum arg)
{
return 0;
}
int
foo(const string &arg)
{
return 0;
}

int
main()
{
foo("hello");
foo(1);
foo(0);

return 0;
}
 
P

Pete Becker

I understand why this is ambiguous, technically, but it seems,
frankly, retarded to consider 0 as ambiguous but 1 as not, just
because 0 == NULL.

Please look up the definition of "retarded" so that you can use it
correctly. This usage is offensive to people who are retarded.
 
V

Victor Bazarov

Tim said:
I understand why this is ambiguous, technically, but it seems,
frankly, retarded to consider 0 as ambiguous but 1 as not, just
because 0 == NULL.

Well, everybody is free to have their own impressions of anything.
Is there any way to defeat this that does not involve changing all
code that uses 0 as an argument to use bignum(0)?

No, and why should there be? Imagine the code without your 'bignum'
where no 'foo(1)' can exist. 'foo(0)' compiles OK (never mind that
it doesn't work, what if it does?) Now, imagine that by adding
an unrelated 'bignum' class and a function overload, you would be
able to change the behaviour of some unrelated code without even
a warning, if it were allowed.

You need to replace all 'foo(0)' with 'foo(bignum(0))', I guess.
#include <string>
using namespace std;

class bignum
{
public:
bignum(int val) {}#include <string>
using namespace std;

class bignum
{
public:
bignum(int val) {}
};

int
foo(bignum arg)
{
return 0;
}
int
foo(const string &arg)
{
return 0;
}

int
main()
{
foo("hello");
foo(1);
foo(0);

return 0;
}

};

int
foo(bignum arg)
{
return 0;
}
int
foo(const string &arg)
{
return 0;
}

int
main()
{
foo("hello");
foo(1);
foo(0);

return 0;
}

V
 
A

anon

Pete said:
Please look up the definition of "retarded" so that you can use it
correctly. This usage is offensive to people who are retarded.

How do you know?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top