Jump to content
  • Advertisement
Sign in to follow this  
Dragon_Strike

generalized typedef templates

This topic is 3988 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 it possible to something like this? template <class Type, int NumOf> class A { } typedef <int, NumOf> AInt<NumOf> typedef <double, NumOf> ADouble<NumOf> i know it isnt supported.. but is there any boost library or similar that has a solution?

Share this post


Link to post
Share on other sites
Advertisement
What about inheritance?
template <class Type, int NumOf>
class A
{
}

template<int NumOf> class AInt : public A<int, NumOf> {};


You can write a conversion operator if you need to implicitly convert from A to AInt, and this way you also have a typechecked templated typedef! You will also find a couple of threads on that subject if you search the forum for "templated typedefs".

Share this post


Link to post
Share on other sites
The general workaround for this is something like the following:


template <int NumOf>
struct AInt
{
typedef A<int, NumOf> Type;
};

// then you can write

AInt<32>::Type foo;



This isn't ideal of course but it does the job.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!