🔒 Locked
C++: Template problem
Advertisement
Original Post
Quote:
Original post by rdfodra
But I don't see any advantage in what you're trying to do.
Well, how could you? That's just a simplified version of what's not working. Here's some more realistic code:
struct EmptyVertex{ // Describes a vertex attribute. For use by vertex array // code. template<typename Type = void, int Size = 0, int Offset = 0> struct empty_type { static const int type = gl_type<Type>::type; static const int size = Size; static const int offset = Offset; }; // The default is that vertex attributes aren't there. struct position_type: public empty_type<> {}; struct normal_type: public empty_type<> {}; struct color_type: public empty_type<> {}; struct secondary_color_type: public empty_type<> {}; struct tex_coord_type: public empty_type<> {}; struct weight_type: public empty_type<> {};};// This adds a position attribute to an existing vertex type,// which may be the EmptyVertex type.template<typename Type = float, int size = 3, typename Base = EmptyVertex>struct PositionVertex : public Base{ // The position Type position[size]; // 'Override' the position_type member with the correct // information about this attribute. struct position_type: public empty_type<Type, size, offsetof(PositionVertex, position) > {}; // The problem is that as empty_type is a member of // EmptyVertex, the compiler doesn't appear to know that it's // a template. It works fine if empty_type is defined outside // EmptyVertex, but I'd rather not have to do that.};
If I understood it correctly, you just have to use empty_type's full name so that the compiler can find it, ie. qualify it with "EmptyVertex::" :
struct PositionVertex : public Base{ struct position_type: public EmptyVertex::empty_type<Type, size, offsetof(PositionVertex, position) > {};};
Have you tried struct position_type: public typename Base::empty_type {}; ?
Or even possibly struct position_type: public typename Base::template empty_type {}; (e.g. if you get parse errors about < and >)
I don't have my C++ templates book nearby (and am too lazy to check in the standard).
Or even possibly struct position_type: public typename Base::template empty_type
I don't have my C++ templates book nearby (and am too lazy to check in the standard).
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement