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

    On 2007-12-19 17:00:49 -0500, Tim H <> 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.
    >


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

    --
    Pete
    Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
    Standard C++ Library Extensions: a Tutorial and Reference
    (www.petebecker.com/tr1book)
     
    Pete Becker, Dec 19, 2007
    #2
    1. Advertisements

  3. Tim H wrote:
    > 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
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Dec 19, 2007
    #3
  4. Tim H

    anon Guest

    Pete Becker wrote:
    > On 2007-12-19 17:00:49 -0500, Tim H <> 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.
    >>

    >
    > 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?
     
    anon, Dec 20, 2007
    #4
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?VGltOjouLg==?=

    Why, why, why???

    =?Utf-8?B?VGltOjouLg==?=, Jan 27, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    999
    Juan T. Llibre
    Jan 27, 2005
  2. sks_cpp
    Replies:
    8
    Views:
    530
    tom_usenet
    Aug 26, 2003
  3. REH
    Replies:
    16
    Views:
    873
    Marcelo Pinto
    Mar 31, 2005
  4. Horace Nunley

    why why why does function not work

    Horace Nunley, Sep 27, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    717
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Sep 27, 2006
  5. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    1,370
    Mark Rae
    Dec 21, 2006
  6. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,838
    Smokey Grindel
    Dec 2, 2006
  7. a eriksson
    Replies:
    1
    Views:
    383
    Victor Bazarov
    Aug 9, 2005
  8. Piotrek
    Replies:
    1
    Views:
    221
    Öö Tiib
    Jan 15, 2014
Loading...