toString() on struct template

Henning Hasemann hhasemann at web.de
Wed Feb 28 12:54:50 PST 2007


I have a struct template with just 2 data members
(thats why I'd actually preferred a struct over a class).

It implements several methods such as overloaded operators
and the pseudo constructor roughly like this:

struct Vector2d(T) {
	T x, y;
	Vector2d!(T) opCall(T x, T y) {
	  Vector2d!(T) v;
	  v.x = x;
	  v.y = y;
	  return v;
	}
	char[] toString() {
	  return format("(%d|%d)", x, y);
	}
}

But the toString actually crashes hard everytime *before* the format-call.
(Btw: Dont be afraid because of the %d's I actually only instantiate the
template with int for testing).

Is there something wrong with my understanding or with the compiler
(tested dmd 1.005 and 1.007)?

Whats the proper way of implementing toString vor structs if not like this?

Henning



More information about the Digitalmars-d mailing list