2

Visual Studio has an issue at the moment such that the following won't compile, giving the error,

error C2797: 'vec::v': list initialization inside member initializer list or non-static data member initializer is not implemented

#include <array>
template<class T, int C>
struct vec
{
 typedef T value_type;
 enum { num_components = C };
 std::array<T, C> v;
 template<typename ...Args>
 vec(Args&&... args) : v{{args...}} {}
};
template<class T>
struct vec2 : vec<T, 2>
{
 vec2(T x, T y) : vec(x, y) {}
};
int main(void)
{
 vec<float, 2> v(10.0f, 20.0f); 
}

The Microsoft Connect ticket for it is closed but there's an MSDN piece about it that recommends, "use explicit construction of inner lists". I don't understand how to do this and the code looks quite alien to me (a beginner).

Can anyone assist with an example using std::array?

asked Jul 1, 2015 at 8:17

1 Answer 1

4

In this particular case you can just add a pair of parentheses:

vec(Args&&... args) : v({{args...}}) {}

This works with VS2013 which, I suppose, you are using.

With VS2015 the code works without modifications.

Also note that for C++ conformance vec2 should be rewritten as

vec2(T x, T y) : vec<T, 2>(x, y) {}

or

using base = vec<T, 2>;
vec2(T x, T y) : base(x, y) {}
answered Jul 1, 2015 at 8:25
Sign up to request clarification or add additional context in comments.

1 Comment

Ah wonderful. Thank you. It looks absolutely horrible though.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.