Archived

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

Inheritance and templates

This topic is 5304 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, im stuck with a problem cos i need my template class to inherit some basic features and i have no idea how to do that. for example template < class TCLASS > void ChainUpdate(TCLASS *FirstClass) { TCLASS iTClass = FirstClass; while (iTClass != NULL) { FirstClass->Update(); iTClass = iTClass->NextClass; } } From that hopefully you can see that TCLASS needs the "Update()" function and the "NextClass" Variable. How can i make TCLASS have these items? probably a basic thing, but its stucked me thanks - Yratelev

Share this post


Link to post
Share on other sites
quote:
Original post by Yratelev
From that hopefully you can see that TCLASS needs the "Update()" function and the "NextClass" Variable. How can i make TCLASS have these items?

The obvious answer is that, if you pass something which doesn''t have those entities, then compilation will fail. Then you write in your documentation for ChainUpdate that it accepts types having those entities (BTW, it''s bad form to have public data members, as NextClass appears to be). You could define an abstract base class that provides the signatures for those entities, and document the intent.

Share this post


Link to post
Share on other sites
Easy, give TCLASS these items.

You don't need any special mechanism to force TCLASS to have Update and NextClass. If TCLASS doesn't have something that the templated code requires an appropriate (although sometimes cryptic) error message will be displayed.

If you're really determined the best I can think of would be to check out the boost::concept_check library.


Joanus D'Mentia


[edited by - joanusdmentia on June 5, 2003 7:35:31 AM]

Share this post


Link to post
Share on other sites