Sign in to follow this  
ill

References to templated classes

Recommended Posts

Is there a way in C++ to not require some templates arguments to be there, especially when it's a pointer?

For example, here is some code:
[CODE]
template <typename T, typename Id, typename Container>
struct ResHelper {
//some code

Id m_resourceId;
ResourceManager<T, Id, Container> * m_manager;
RefCountPtrRoot<T, ResHelper<T, Id, Container> >* m_root;
};

template <typename T, typename Id = uint64_t, typename Container = std::map<Id, ResourceInfo> >
class ResourceManager {
//code goes here
};
[/CODE]


I would really like to write it more like this:
[CODE]
template <typename Id>
struct ResHelper {
//some code

Id m_resourceId;
ResourceManager<?, Id, ?> * m_manager;
RefCountPtrRoot<?, ResHelper<Id> >* m_root;
};

template <typename T, typename Id = uint64_t, typename Container = std::map<Id, ResourceInfo> >
class ResourceManager {
//code goes here
};
[/CODE]

Here I'm avoiding other template arguments because this is a struct that holds an id with some variable type.
The rest are just pointers. I put question marks in places where a type would normally go for that class.

So far the only way I can get my code to compile is to do it the way I did it above. This gets really annoying and messy when I have dependancies all over the place and end up needing classes that had very simple template arguments suddenly need like 6 template arguments because they have all these pointers.

I had a class before that contained a ResHelper<typename Id> but after doing some work now it needs to be ResHelper<typename T, typename Id, typename Container>. Now the templated class that contains the ResHelper<> needs to also provide template arguments for these extra things.

Share this post


Link to post
Share on other sites
You could derive your ResourceManager from an interface type that's only templated on the Id and use pointers to that type.

Share this post


Link to post
Share on other sites
I actually came up with an idea. The giant templated monster class will be internal. I'll make a wrapper around it that won't have all these templated arguments.

The giant templated class was supposed to be a kind of base class but I can just make wrapper classes that contain it. It'll also avoid virtual functions and things like that...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this