struct opCast to void* and back

Robert Clipsham robert at octarineparrot.com
Sun Apr 11 07:45:46 PDT 2010


On 11/04/10 15:41, Nrgyzer wrote:
> I want to do the following:
>
> struct MyStruct {
>
> 	char[] structName;
>
> 	public char[] toString() {
>
> 		return structName;
>
> 	}
> 	
> }
>
> ...
>
> class MyClass {
>
> 	private static void function(void*) callBack;
> 	private static void* callBackValue;
> 	...
> 	static this() {
> 		MyStruct test = MyStruct();
> 		test.structName = "Struct name";
> 		callBack =&cb;
> 		callBackValue =&test;
> 	}
> 	...
> 	public void cb(void* value) {
>
> 		MyStruct temp = *((cast(MyStruct*) value));
> 		writefln(temp);
>
> 	}
>
> }

Why the need for void* everywhere? Surely you could save the effort and 
store it as a MyStruct?



More information about the Digitalmars-d mailing list