C++ base class needs at least one virtual method

evilrat evilrat666 at gmail.com
Wed Feb 6 08:02:27 UTC 2019


On Wednesday, 6 February 2019 at 07:38:04 UTC, ezneh wrote:
>
> Thanks for the trick, I'll try  it and see how it goes.
> Since the class have nothing in them, I just made some "alias 
> otherclass = baseclass" statements and it seems it is working 
> (at least it's compiling, have to really test that too). From 
> what I saw about the code is that those types are just 
> "placeholders" because they aren't used directly by the API.
>

It still might be necessary to add empty struct with 'extern(C++, 
class)' because alias is, well, just alias, and it needs a real 
type because C++ signatures do contains parameters types, and 
obviously there will be no methods that accepts derived class so 
it will fail to link.
That's what that 'alias this' is for. And since this is not 
direct inheritance it will most likely won't work when object 
expected to be passed by value (at least not without casting to 
void* then to base*, i.e. 
'someFunc(*cast(baseclass*)cast(void*)&derivedObj)')


More information about the Digitalmars-d-learn mailing list