Skip to main content
Post Closed as "Duplicate" by cigien c++
deleted 31 characters in body; edited title
Source Link
John Kugelman
  • 364.5k
  • 70
  • 555
  • 600

C++ : Initializing Initialize an array in a struct

Is there already a way where I can initalizeinitialize an array directly in thea struct  ?

like Like this ?:

struct S { int arr[50] = {5}; } 

I know this only initializes the first element of the array, but is there any way to write something similar with the G++ compilerg++ but that can initialize all elements of the array with 5?

I've read that with GCC Compilergcc, we can use designated intiializersintializers int arr[50] = {[0 ... 49] = 5}; but this won't be possible in C++.

C++ : Initializing an array in a struct

Is there already a way where I can initalize an array directly in the struct  ?

like this ?

struct S { int arr[50] = {5}; } 

I know this only initializes the first element of the array, but is there any way to write something similar with the G++ compiler but that can initialize all elements of the array with 5?

I've read that with GCC Compiler, we can use designated intiializers int arr[50] = {[0 ... 49] = 5}; but this won't be possible in C++.

Initialize an array in a struct

Is there already a way where I can initialize an array directly in a struct? Like this:

struct S { int arr[50] = {5}; } 

I know this only initializes the first element of the array, but is there any way to write something similar with g++ but that can initialize all elements of the array with 5?

I've read that with gcc we can use designated intializers int arr[50] = {[0 ... 49] = 5}; but this won't be possible in C++.

added 1 character in body
Source Link

Is there already a way where I can initalize an array directly in the struct ?

like this ?

struct S { int arr[5]arr[50] = {5}; } 

I know this only initializes the first element of the array, but is there any way to write something similar with the G++ compiler but that can initialize all elements of the array with 5?

I've read that with GCC Compiler, we can use designated intiializers int arr[5]arr[50] = {[0 ... 4]49] = 15}; but this won't be possible in C++.

Is there already a way where I can initalize an array directly in the struct ?

like this ?

struct S { int arr[5] = {5}; } 

I know this only initializes the first element of the array, but is there any way to write something similar with the G++ compiler but that can initialize all elements of the array with 5?

I've read that with GCC Compiler, we can use designated intiializers int arr[5] = {[0 ... 4] = 1}; but this won't be possible in C++.

Is there already a way where I can initalize an array directly in the struct ?

like this ?

struct S { int arr[50] = {5}; } 

I know this only initializes the first element of the array, but is there any way to write something similar with the G++ compiler but that can initialize all elements of the array with 5?

I've read that with GCC Compiler, we can use designated intiializers int arr[50] = {[0 ... 49] = 5}; but this won't be possible in C++.

Source Link

C++ : Initializing an array in a struct

Is there already a way where I can initalize an array directly in the struct ?

like this ?

struct S { int arr[5] = {5}; } 

I know this only initializes the first element of the array, but is there any way to write something similar with the G++ compiler but that can initialize all elements of the array with 5?

I've read that with GCC Compiler, we can use designated intiializers int arr[5] = {[0 ... 4] = 1}; but this won't be possible in C++.