opCall example

Saaa empty at needmail.com
Tue Jan 29 21:49:03 PST 2008


What does different exactly mean in this example?
I read that s is of type S thus should be calling opCall (S v), but it 
doesn't.

If opCall is overridden for the struct, and the struct is initialized with a 
value that is of a different type, then the opCall operator is called:

struct S{   int a;

    static S opCall(int v)
    {	S s;
	s.a = v;
	return s;
    }

    static S opCall(S v)
    {	S s;
	s.a = v.a + 1;
	return s;
    }
}

S s = 3;	// sets s.a to 3
S t = s;	// sets t.a to 3, S.opCall(s) is not called









More information about the Digitalmars-d-learn mailing list