1) The problem with your approach is that the function can only create one instance, since there is only one shared variable. Unless I am missing something, you have created a singleton.
I have moved on from using a linked list because it polutes the global namespace. If objects are to form a library and be generally included in other codes then the global namespace becomes a precious resource. For this reason in my stack example I allocate the memory directly rather than using a linked list.
viewtopic.php?t=10319&start=15
I've been pushing Fred for anonymous functions to avoid having to have function names in the global namespace, but he doesn't like the idea.
viewtopic.php?t=10372&highlight=global+namespace+ruby
2) I prefer structures because there definition tells you what it is, which an Array does not.
I think that
is less clear thanVTPBFriendlyFunctions(0) = @get_Name()
The array version could be improved if you used a constant rather than an explicit 0, but why bother when you have structures available?VTPBFriendly_vTable\get_name = @get_Name()
Also, structures now support the same inheritance features as interfaces.
Having the vTable as a global variable is actually an advantage, since the one vTable is shared between all instances. The vTable doesn't have to be global anymore. You can just have it as a static variable in the creation function. Arrays, on the other hand, are always global.
3) Personally I prefer the use of a creation function. I hate the whole use of IIDs in COM because it is just so complicated and a single point of failure which so often fails.
I take the lead for creation functions from the Eiffel language. So much clearer, with no need for all those complicated mechanisms.
Knowing the name of the function is no more difficult than knowing the Prog ID, and a lot easier than knowing the GUIDs. Like Eiffel, you can have several creation procdures. For example, a com object might have
So much clearer than using operator overloading, especially if you have an autocompleting editor like jaPBe. Note that two of the procedures take a string argument.COM_Create_From_Binary_IID(IID.guid)
COM_Create_From_String_IID(IID.s)
COM_Create_From_ProgID(ProgID.s)
COM_Create_From_Unicode_ProgID(*ProgID_buffer)
If the object was packaged in a library then all the user would need is the interface definition and these creation procedure names. No need to register or any other runtime burden.
If you want to have objects provided at runtime then simply put them in a dll, only the creation functions need exporting.
Of coure, all these are just my own religous beliefs. I am stating the reasons for my personal choices. YMMV.