Jump to content
  • Advertisement
Sign in to follow this  
ill

References to templated classes

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

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:

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
};



I would really like to write it more like this:

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
};


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