function resolution observations

P

puzzlecracker

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;
}
 
V

Victor Bazarov

puzzlecracker said:
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.
 
P

puzzlecracker

Victor said:
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.
 
J

James Aguilar

puzzlecracker said:
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
 
V

Victor Bazarov

puzzlecracker said:
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.
 
P

puzzlecracker

Victor said:
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.
 
V

Victor Bazarov

puzzlecracker said:
[...]
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
 
K

Karl Heinz Buchegger

Victor said:
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
 

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

Staff online

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top