struct constructors and function parameters

Simen kjaeraas simen.kjaras at gmail.com
Tue Nov 9 15:57:47 PST 2010


Adam Burton <adz21c at gmail.com> wrote:

> Hi,
> should the below work?
>
> struct A
> {
>     public this(B b) {}
> }
>
> struct B {}
>
> void foo(A a) {}
>
> void main()
> {
>     B b;
>     foo(b);     // Fails
> }
>
> The constructor parameter doesn't need to be a struct, it could be an  
> int.
> The workaround is to explicity call the constructor.

Far as I know, that's not supposed to work, no. Guess it has to do with
overloading:

struct foo {
     this( int n ){}
}

void bar( foo f ) {}
void bar( int n ) {}

bar( 3 ); // which do I call?

-- 
Simen


More information about the Digitalmars-d-learn mailing list