function resolution observations

Discussion in 'C++' started by puzzlecracker, Apr 26, 2005.

  1. back to the same question: why in this code copy contor in A is called
    instead of to flag the AMBIGUITY????? I have tried different compilers
    for that.

    #include<iostream>

    class B; //declaration
    class A{
    public:
    A ( ){ }
    A ( const B& b){ /////////////////////////////////////
    std::cout<<"A constructor is called\n";
    }
    };
    class B{

    public:
    operator A() const { //////////////////////////

    std::cout<<"In B, A operator is called\n";
    A a;
    return a;
    }

    };
    void f (const A& a)
    {
    std::cout<<"Ambiguity\n";

    }


    int main(){

    B b;
    f(b);

    return 0;
    }
     
    puzzlecracker, Apr 26, 2005
    #1
    1. Advertising

  2. puzzlecracker wrote:
    > back to the same question: why in this code copy contor in A is called
    > instead of to flag the AMBIGUITY????? I have tried different compilers
    > for that.


    Because all compilers you tried are buggy, maybe...

    Comeau doesn't want to compile it. Visual C++ v7.1 doesn't want to
    compile it.
     
    Victor Bazarov, Apr 26, 2005
    #2
    1. Advertising

  3. Victor Bazarov wrote:
    > puzzlecracker wrote:
    > > back to the same question: why in this code copy contor in A is

    called
    > > instead of to flag the AMBIGUITY????? I have tried different

    compilers
    > > for that.

    >
    > Because all compilers you tried are buggy, maybe...
    >
    > Comeau doesn't want to compile it. Visual C++ v7.1 doesn't want to
    > compile it.


    thx, my question is whether these two have the same priority at
    resolution stage.
     
    puzzlecracker, Apr 26, 2005
    #3
  4. "puzzlecracker" <> wrote in message
    news:...
    >
    > thx, my question is whether these two have the same priority at
    > resolution stage.


    Isn't it the case that the question of their priority doesn't make sense, in
    that the ambiguity makes the program malformed in the first place? Their
    priority isn't defined, because it is wrong, in a C++ program, to have a
    situation in which there could be ambiguity as to which should be called.

    - JFA1
     
    James Aguilar, Apr 26, 2005
    #4
  5. puzzlecracker wrote:
    > Victor Bazarov wrote:
    >
    >>puzzlecracker wrote:
    >>
    >>>back to the same question: why in this code copy contor in A is

    >
    > called
    >
    >>>instead of to flag the AMBIGUITY????? I have tried different

    >
    > compilers
    >
    >>>for that.

    >>
    >>Because all compilers you tried are buggy, maybe...
    >>
    >>Comeau doesn't want to compile it. Visual C++ v7.1 doesn't want to
    >>compile it.

    >
    >
    > thx, my question is whether these two have the same priority at
    > resolution stage.
    >


    They both are user-defined conversions. Of course they have the same
    priority. Do you have a copy of the Standard? If yes, look in the
    Clause 13. If you don't have a copy, get one.
     
    Victor Bazarov, Apr 26, 2005
    #5
  6. Victor Bazarov wrote:
    > puzzlecracker wrote:
    > > Victor Bazarov wrote:
    > >
    > >>puzzlecracker wrote:
    > >>
    > >>>back to the same question: why in this code copy contor in A is

    > >
    > > called
    > >
    > >>>instead of to flag the AMBIGUITY????? I have tried different

    > >
    > > compilers
    > >
    > >>>for that.
    > >>
    > >>Because all compilers you tried are buggy, maybe...
    > >>
    > >>Comeau doesn't want to compile it. Visual C++ v7.1 doesn't want to
    > >>compile it.

    > >
    > >
    > > thx, my question is whether these two have the same priority at
    > > resolution stage.
    > >

    >
    > They both are user-defined conversions. Of course they have the same
    > priority. Do you have a copy of the Standard? If yes, look in the
    > Clause 13. If you don't have a copy, get one.


    irrelevant but on the same note: is worth to read the standard
    thoroughly (epithet for "is it a must?")?

    thanks victor.
     
    puzzlecracker, Apr 26, 2005
    #6
  7. puzzlecracker wrote:
    > [...]
    > irrelevant but on the same note: is worth to read the standard
    > thoroughly (epithet for "is it a must?")?


    Definite no to that (if I understand what you're asking). However, it
    does help if you are unsure whether the compiler you have is faulty or
    it's some kind of assumption you might have acquired somewhere.

    Of course, to be precise in my answer I should say that yes, the Standard
    must be read thoroughly to be useful. Words that comprise the Standard
    have been put there as the result of careful selection and after weighing
    essentially every word. They certainly deserve to be read thoroughly.
    But I think you weren't asking that.

    V
     
    Victor Bazarov, Apr 26, 2005
    #7
  8. Victor Bazarov wrote:
    >
    > puzzlecracker wrote:
    > > back to the same question: why in this code copy contor in A is called
    > > instead of to flag the AMBIGUITY????? I have tried different compilers
    > > for that.

    >
    > Because all compilers you tried are buggy, maybe...
    >
    > Comeau doesn't want to compile it. Visual C++ v7.1 doesn't want to
    > compile it.


    And so does VC++ 6.0

    --
    Karl Heinz Buchegger
     
    Karl Heinz Buchegger, Apr 27, 2005
    #8
    1. Advertising

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. David Mark

    .NET observations

    David Mark, Feb 3, 2007, in forum: ASP .Net
    Replies:
    8
    Views:
    362
    =?Utf-8?B?U01Ib2Zm?=
    Apr 10, 2007
  2. Newbie observations

    , Dec 18, 2007, in forum: Python
    Replies:
    9
    Views:
    269
    Bruno Desthuilliers
    Dec 19, 2007
  3. cwdjrxyz
    Replies:
    7
    Views:
    512
    ddg_linux
    Sep 3, 2008
  4. Eric Sosman

    Observations on operator overloading

    Eric Sosman, Apr 1, 2010, in forum: C Programming
    Replies:
    9
    Views:
    356
    Eric Sosman
    Apr 11, 2010
  5. Eric Snow
    Replies:
    7
    Views:
    283
    Steven D'Aprano
    Aug 6, 2011
Loading...

Share This Page