Jump to content
  • Advertisement
Sign in to follow this  
michael879

inheritance within templates in C++

This topic is 4416 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

ok I know java has a way to specify that you want the generic type to be a subclass or a super class of a specific class (<T extends Object>, <? super SomeCLass>). Is there any way to do this in C++? Im trying to make a particle engine and I want a base particle class that contains the minimum data needed. However you can make a particle system out of anything that inherits from particle. I know I could use virtual functions for this but Id rather keep the particles as small as possible. 4 bytes per particle is a lot if your using 1000s of particles.

Share this post


Link to post
Share on other sites
Advertisement
In a nutshell, you can just skip requiring an inheritance relationship as part of the template declaration. With latent typing in the C++ template mechanism, as long as the instantiated type supports the operations you perform in the template implementation (which can include casting to the base type) then the template will compile. If the type does not support the operations performed by the template implementation then the code will fail to compile. Admittedly this gives a less clear error message than the Java generics.

Share this post


Link to post
Share on other sites
It's part of the boost library. A library that supposedly fills many missing voids in standard C++. It's pretty useful, but I myself have never really had a need for it. :p


-Etyrn

Share this post


Link to post
Share on other sites
Quote:
Original post by Polymorphic OOP
Well, with an extra set of parenthesis around the macro argument (otherwise it'd be interpretted as two arguments instead of one).


[razz] [smile]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!