Sign in to follow this  

Help with some template code

This topic is 4338 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[i];
        }

    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
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[i];
}

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

This topic is 4338 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this