Jump to content
  • Advertisement


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


Templated Classes: Can I specify the type of the template to be the class itself?

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

I've written a templated cDatabase class, and for my game manager, I want it to have an array of these things. This is to facilitate the control of multiple databases. For example, I'd like one database to track my current objects, and another to take care of the bitmaps. Right now I can add and remove entries, and I plan to add the ability to return entries based on keys, sort it, etc... Right now, my templated class is set up so that I can do this:
cDatabase<cObject> Database;
However, I can't do this, which is what I would need to have a database of databases:
cDatabase<cDatabase> MasterDatabase;
One way to do it would just be to have a cDatabase**, and then create NEW cDatabase and assign them to the master list. The problem with this is that it is sort of redundant, seeing as how my cDatabase class can add/remove entries anyway. I assume that this is a limit of templates, but please let me know if there is a way to do this (perhaps I'm missing something obvious) [edited by - Peon on October 16, 2003 3:30:59 PM]

Share this post

Link to post
Share on other sites
Well I kind of thought about it some and realized I can''t really do what I want. The above example that you posted would work, but the problem is that I wanted to be able to have lots of types of databases. For example, I would have one that is cDatabase (object) and another that is cDatabase (HBITMAP); I would then have a database of databases, to track them more easily. However, the more I think about, the more I realize this is impossible

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
I''m not sure if it would work but...

You could create a baseclass named, let say, CBaseDB and derive your CDatabase template from it.

And instead of using CDatabase<CDatabase<COject> > Database;
you could use CDatabase<CBaseDB> Database;

You could then past any CDatabase<...> to your database.

Share this post

Link to post
Share on other sites

  • 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!