简体   繁体   中英

array initialization requires a brace-enclosed initializer list

My class Matrix4x4 has a constructor that takes 9 values and copies them into an internal T value[4][4] member through an initializer list. However, it doesn't compile, and I'm not entirely sure why. Specifically, the error says: array initialization requires a brace-enclosed initializer list .

I'm using Visual Studio 2015.

template<typename T>
Matrix4x4<T>::Matrix4x4(
    T aa, T ba, T ca,
    T ab, T bb, T cb,
    T ac, T bc, T cc
    )
    : value({
        { aa, ba, ca,  0 },
        { ab, bb, cb,  0 },
        { ac, bc, cc,  0 },
        { 0,  0,  0,  1 }
    })
{

}

If you have access to a C++11 compiler, here's one solution.

Remove the ( and ) from the initializer of value. Use:

Matrix4x4::Matrix4x4(T aa, T ba, T ca,
                     T ab, T bb, T cb,
                     T ac, T bc, T cc)
   : value{ { aa, ba, ca,  0 },
            { ab, bb, cb,  0 },
            { ac, bc, cc,  0 },
            { 0,  0,  0,  1 } }
{
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM