Jump to content
  • Advertisement
Sign in to follow this  
D_Tr

Templates and Typedefs

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

Hello ppl, I 've just written the following small fixed-point class:
template<typename I, Int32 N>
class Fixed
{
public:
	Fixed();
	Fixed(Float64 a_Float64) : value(a_Float64 * Pow(2.0, N))
	{};
	
	operator Float64()
	{
		return (Float64)value * Pow(2.0, -N);
	};
	
	Fixed<I, N> &operator=(Float64 a_Float64)
	{
		value = a_Float64 * Pow(2.0, N);
	};

private:
	I value;
};


where I is the underlying integral type and N is the number of bits to the right of the decimal point. Now, i would like to do some typedefs like the following:
typedef Fixed<UInt64, N> UFixed64<N>;
but the above typedef generates errors (compiled with g++ 4.something):
Fixed.hpp:23: error: ‘N’ was not declared in this scope
Fixed.hpp:23: error: template argument 2 is invalid
Fixed.hpp:23: error: expected initializer before ‘<’ token


Is there any (preferably standard) way to do this kind of typedefs?

Share this post


Link to post
Share on other sites
Advertisement
Unfortunately, C++ does not include support for templated typedefs (which is what it looks like you're wanting to do).

For more info on this, Google 'C+ templated typedefs' (you might also find some examples of ways you can work around this problem).

Share this post


Link to post
Share on other sites
Problem is that the template is expecting a number, and not "N" for the template. I suggest creating a macro:

#define UFixed64(N) Fixed<UInt64,N>

Share this post


Link to post
Share on other sites
Thanks for the tips :). I will write the rest of the class for now and i 'll decide on a solution later.

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!