vendredi 25 septembre 2020

How to initialize only a few elements of a global array in c++11 with gcc toolchain?

I have the following code:

#include <iostream>

int array[10] = {
  [2] = 200,
  [5] = 500
};

int main() {
  std::cout << "Hello World!\n";
  std::cout << array[5];
  return 0;
}

When I compile with g++ -std=c++11 -o main main.cpp, I get the following error:

main.cpp:6:1: sorry, unimplemented: non-trivial designated initializers not supported
 };
 ^
main.cpp:6:1: sorry, unimplemented: non-trivial designated initializers not supported

Is there any way to do this with g++? Clang works fine.

Aucun commentaire:

Enregistrer un commentaire