Function Overloading
I was wondering if there was an easier way to overload a function to accept different types of data (int, float), when the type wouldn''t matter. An example of this would be a memory manager, you have a DeAllocate() function, no matter what type of pointer is passed, you want to just delete it, and it won''t matter what type. (this is assuming no arrays)
Thank you very much Desert Fox!! I knew I had read about something like this somewhere, and I was looking through my unorganized tutorials and I couldn''t find it.
And possibly another good solution would be using a void *, which accepts any datatype (and furthermore you could cast them to an int, float, etc)
[edited by - _twiggie_ on January 24, 2004 7:48:26 AM]
void DeAllocate(void *ptr){ delete ptr;}
[edited by - _twiggie_ on January 24, 2004 7:48:26 AM]
Except in that case a destructor never gets called if ptr points to an object and not a primitive =)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement