Public Group

#### Archived

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.

## 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 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 on other sites
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.

1. 1
2. 2
3. 3
Rutin
21
4. 4
frob
18
5. 5

• 33
• 13
• 10
• 10
• 12
• ### Forum Statistics

• Total Topics
632568
• Total Posts
3007119

×