Compynerd255 wrote:
Wow... that looks wonderful - I never would have thought of overriding operators like that. How would this code be used, however?
Constructors would completely replace the old braces-initializtion {...} syntax:
Code:
struct A {
int x, y;
new(int n) { x = n; y = -n; }
}
struct B {
int x, y;
// This default constructor is implied:
// new(int x, y) { this.x = x; this.y = y; }
}
A allAtOnce = A(1,2);
A separate; separate = A(1,2);
inferred := A(1,2);
A newInitialized = new A(1,2);
A newUninitialized = new A; // NO construction done
B worksAllTheSameAsA = B(1,2);
Arrays stay the same though:
Code:
[]A array = &[]A{A(1,2), ...}; // static instance
[]A smaller = {A(1,2), ...}; // this is ok too
infArray := &[]A{A(1,2), ...};
[]A newArr = new [size]A; // no construction of A's
[]A newInit = new []A{A(1,2),...};
[]*A arrOfPtr = {new A(1,2), new A, &someA, ...}; // etc.