简体   繁体   中英

c++ aggregates initialization with c-style arrays

In c++14 I have the following type:

std::tuple<int[2], int>;

How can I properly initialize it? This

std::tuple<int[2], int> a {{2,2},3};

gives me this error:

/usr/include/c++/5/tuple:108:25: error: array used as initializer

While this:

std::tuple<std::array<int,2>, int> a {{2,2},3};

works, but I want to be able to work with standard C-style arrays

std::tuple is not an aggregate and doesn't provide a list-initializer constructor . This makes list initialization with that type impossible to use with C-arrays.

You can however use std::make_tuple :

auto a = std::make_tuple<int[2], int>({2,2},3);

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