offsetof fails when parameter to a template

Mark Guidarelli guido at grumpy-cat.com
Sat Feb 3 23:10:44 PST 2007


import std.stdio;

struct foo(T) {
	int a;
	T b;
	int c;
}

void output(int offset) {
	writefln("offset = ", offset);
}

void main() {
	// works
	alias foo!(int) bar;
	output(bar.b.offsetof);
	// fails
	// test.d(20): Error: 'this' is only allowed in non-static member functions, not main
	// test.d(20): Error: this for b needs to be type foo not type int
	output(foo!(int).b.offsetof);
}


More information about the Digitalmars-d-bugs mailing list