C++ interface vs D and com

Adam Sansier via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jul 12 16:55:55 PDT 2016


On Tuesday, 12 July 2016 at 22:55:05 UTC, Adam Sansier wrote:
>> So, the problem now, is how to take the interface, which is 
>> simple, no implementation, and either create the 
>> implementation or create a sort of simple empty proxy that can 
>> be used to instantiate the interface?
>>
>
> I mean automatically of course. I believe D already has some 
> library solution for this but haven't looked them up yet.

Ok, Another hack:

		iInterface x;
		void** y = cast(void**)&x;
		*y = malloc(iInterface.sizeof);
		
		x.__vptr = cast(immutable(void*)*)(*ptr);
		x.func();

works.

x is the object of type iInterface. It has no object associated 
with it, basically create one using malloc and set it's vtable.

this avoids the need to create the class.





More information about the Digitalmars-d-learn mailing list