Jump to content

  • Log In with Google      Sign In   
  • Create Account


References to templated classes


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 ill   Members   -  Reputation: 320

Like
0Likes
Like

Posted 01 May 2012 - 03:55 PM

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.

Sponsor:

#2 SiCrane   Moderators   -  Reputation: 9157

Like
0Likes
Like

Posted 01 May 2012 - 04:02 PM

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

#3 ill   Members   -  Reputation: 320

Like
0Likes
Like

Posted 01 May 2012 - 05:43 PM

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...




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS