Why is this ambiguous?

Discussion in 'C++' started by Tim H, Dec 19, 2007.

  1. Tim H

    Tim H Guest

    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;
    }
     
    Tim H, Dec 19, 2007
    #1
    1. Advertisements

  2. Tim H

    Pete Becker Guest

    Please look up the definition of "retarded" so that you can use it
    correctly. This usage is offensive to people who are retarded.
     
    Pete Becker, Dec 19, 2007
    #2
    1. Advertisements

  3. Well, everybody is free to have their own impressions of anything.
    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.
    V
     
    Victor Bazarov, Dec 19, 2007
    #3
  4. Tim H

    anon Guest

    How do you know?
     
    anon, Dec 20, 2007
    #4
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.