• Advertisement

Archived

This topic is now archived and is closed to further replies.

[C++] class Object ??

This topic is 5325 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, Is there something similar to the java "uber" class "Object" in C++ ?? I''m writing a simple stack class, so I need to be able to put anything on the stack. In Java I could use this method "AddMyObject(Object item);" but how do I do this in C++ ?? Thanks !!

Share this post


Link to post
Share on other sites
Advertisement
No, there''s no class from which all classes inherit. Assuming that each particular list object will only contain objects of one type, use templates. Otherwise, you may want to check out Boost''s "any" class.


How appropriate. You fight like a cow.

Share this post


Link to post
Share on other sites
Well there are a few thing that you could do about that: use a boost any as it is a holder for any object (may have performance penalties you''ll have to check), you could just have is hold void pointers as those can point to anything, or what I would do is make a "super" object and have everything that I would want in the stack to inherit it.

Share this post


Link to post
Share on other sites

  • Advertisement