compiler priorities in conversion

Hi,

I've read that the compiler is ready to take up to 2 steps of conversion , by the following order :
1.exact match
2.premotion
3.conversion
4.user defined conversion

can you please give me an example where the compiler can't take 3 steps of conversion ?

thanks ,
dave
Compile this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
struct Foo{ Foo( int ) {} };

struct Bar{ Bar( Foo ) {} };

struct Baz{ Baz( Bar ) {} };

void bar( Bar b ) {}

int main() {
   Foo a = 5;// int -> Foo is OK
   Foo b = 0.5;// float -> int -> Foo is OK
   Bar c = 5;// int -> Foo -> Bar is OK
   bar( 5 );//int -> Foo -> Bar fails
   Baz d = 5;//int -> Foo -> Bar -> Baz fails
}
Last edited on
Hi ,

Please pay attention that the line " Bar c = 5;// int -> Foo -> Bar " doesn't compile also , which is pretty weird since the conversions are
1. int to Foo
2. Foo to Bar

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
using namespace std;

class Foo
{
public:
	Foo(int) {}
};

class Bar
{
public:
	Bar( Foo ) {}
};

class Baz
{
public:
	Baz( Bar ) {}
};

void bar( Bar b ) {}

int main() {
   Foo a = 5;// int -> Foo is OK
   Foo b = 0.5;// float -> int -> Foo is OK
   Bar c = 5;// int -> Foo -> Bar 
   bar( 5 );//int -> Foo -> Bar fails
   Baz d = 5;//int -> Foo -> Bar -> Baz fails
   return 0;
}

why is that ? thanks
That line compiled for me.. Even though the next one, which did the same thing, did not. I suppose we're just using different compilers. I failed to find anything about this in the standard.
What compiler are you using ?
I use Eclipse g++

thanks !
MSVC++2010.
Topic archived. No new replies allowed.