&this pointer

e-t172 idontlikespam at nospam.com
Sun Feb 11 12:14:26 PST 2007


The following does not work :

import std.stdio;

class Test
{
	this()
	{
		void* ptr = cast(void*) this;

		(*(cast(Test*) ptr)).foo();
	}

	void foo()
	{
		writefln("OK");
	}
}

int main()
{
	auto test = new Test();

	return 0;
}

Result : segmentation fault

Could one explain why ?


More information about the Digitalmars-d-learn mailing list