You have a set of classes names Object<something> - are they related?
If they are not curently, could they all descend from a single parent class?
If so, rather than use void* you could use <parent class>* as the parameter, then just call object->release() and let polymorphism take care of calling the right one for you.
Much cleaner code, and easier when you later add a new Object type as it will be handled in this routine automatically.
See http://www.cplusplus.com/doc/tutorial/polymorphism.html for info on polymorphism if you need additional info - it's a very powerful feature of OO.
No, they aren't much related. I considered making a parent class, but there isn't even one element or method every object has.. other than release() come to think of it >_>
Hmm, I may do some reconstruction then.
However I am still curious, is there anything fundamentally wrong with using the above code?
IMO you can write your programs anyway you wish, however to me it
does raise some questions
Q1
if ObjectController is the master for allocating and deallocating IDO objects (it's name give the impression that it is)
why when releasing objects do you have to give it both the pointer to the object
and tell it what type of object of object is being released?
Maybe if ObjectController returned a HANDLE when it created an object, then, when you want to relase the object - pass the HANDLE to the ObjectController, and ObjectController releases the object, - the IDO wouldn't need it's own release function.
Q2
Out of interest - What does the release function do.
Is the IDO object trying to use the delete operator on itself.
(This is legal by the way).
My summary is - it depends on how IDO object are allocated and by whom.
Maybe some of the more experienced programmers can expand on this.
It wouldn't be first time nor the last that an (abstract) parent class contains only a single pure virtual method. I would agree with Faldrax to use inheritance/derivation as a perfectly acceptable solution to the problem, even if release() is the only common part.
1 2 3 4
class Releasable {
public:
virtualvoid release() = 0;
};