Jump to content
  • Advertisement
Sign in to follow this  
Rebooted

Help with some template code

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

The following code is giving me this error with Visual C++ 8: C3860: template argument list following class template name must list parameters in the order used in template parameter list.
template <size_t dimensions, typename T> struct Vector
{
    BOOST_STATIC_ASSERT( (dimensions >= 2) && (dimensions <= 4) );
};

class VectorMembers
{
    public:

        static T& Get(Vector<dimensions, T> &v, size_t i)
        {
            return v.*members;
        }

    private:

        typedef T Vector<dimensions, T>::* const vec[dimensions];

        static const vec members;
};

template <typename T> struct Vector<2, T>
{
    T x, y;
};

template< typename T >
const typename VectorMembers<2, T>::vec VectorMembers<2, T>::members = { &Vector<2, T>::x, &Vector<2, T>::y };


The problem is with initilizing the static member of VectorMembers. I need to do this slightly differently to get the compiler to do what I want, but I don't know how. Thanks for any help.

Share this post


Link to post
Share on other sites
Advertisement
You're trying to partially specialize the static member without partially specializing the class it belongs to. Getting these to align seems to get things working on G++:

template <size_t dimensions, typename T> struct Vector
{
BOOST_STATIC_ASSERT( (dimensions >= 2) && (dimensions <= 4) );
};

template <size_t dimensions, typename T> class VectorMembers;

template < typename T > class VectorMembers<2, T>
{
public:

static T& Get(Vector<2, T> &v, size_t i)
{
return v.*members;
}

private:

typedef T Vector<2, T>::* const vec[2];

static const vec members;
};

template <typename T> struct Vector<2, T>
{
T x, y;
};

template< typename T >
const typename VectorMembers<2, T>::vec VectorMembers<2, T>::members = { &Vector<2, T>::x, &Vector<2, T>::y };



Instead of this, I'd recommend moving the partial specialization into VectorMembersBase - e.g.:

template < size_t dimensions , typename T > class VectorMembersBase;

template < typename T > class VectorMembersBase< 2 , T > {
protected:
typedef T Vector<2, T>::* const vec[2];
static const vec members;
};

template< typename T >
const typename VectorMembersBase<2, T>::vec VectorMembersBase<2, T>::members = { &Vector<2, T>::x, &Vector<2, T>::y };

//VectorMembersBase< 3 , T >
//VectorMembersBase< 4 , T >
//VectorMembersBase< N , T >

template < size_t dimensions , typename T > class VectorMembers< dimensions , T > : public VectorMembersBase< dimensions , T > {
...Get implementation...
}

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!