Extern Type

BlitzMax Forums/BlitzMax Programming/Extern Type

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.


Why two padding functions for example, and why do the functions need to be virtual?



It is generally good practice when writing C++ classes with virtual methods to also provide a virtual destructor.

I wont go into the 'why' of this, but it turns out that virtual destructors (under MINGW and MSVC anyway) actually require 2 versions - one for dynamic 'delete' style destruction and the other for static 'going out of scope' style destruction. (From memory - I looked into all this when I was learning c++ ages ago now and it's a bit hazy now).

Whatever, a virtual destructor is the equivalent of 2 methods, hence the 2 _pad() methods.

COM objects, however, do not use virtual destructors, so there is no padding required.

As for why the c++ methods have to be virtual, this is because c++ non-virtual methods aren't actually methods in the Max sense - they are just concrete functions. And, due to c++ 'name mangling', finding the 'symbols' for such functions is tricky.


also, i have a Q about return types. how do you return an instance instead of a pointer?



You can't.

c++ 'values' can have copy constructors/destructors and all sorts of weird stuff in them that is well beyond Max's ability to deal with.