Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct A {
- A() {
- printf("A() calledn");
- }
- A(int i, int j) {
- printf("A(%d, %d) calledn", i, j);
- }
- };
- struct B {
- A tab[100];
- B(int i, int j) {
- // I would like to call A(i, j) for each tab entries instead of the default constructor
- printf("B(%d, %d) calledn", i, j);
- }
- };
- int main() {
- B b(1, 7);
- return 0;
- }
- struct B {
- A tab[100];
- template<size_t... Is>
- B(int i, int j, std::index_sequence<Is...>) : tab{ {(void(Is), i), j }... } {}
- B(int i, int j) : B(i, j, std::make_index_sequence<100>()) {}
- };
Add Comment
Please, Sign In to add comment