Can't brace initialize struct even with -std=c++11 enabled in CB

Hey guys, sorry if this is a simple fix. Tried doing some searching but everything I've seen on my error just says to enable -std=c++ on the GNU compiler but I am still getting errors in build. Tried asking over at the CB forums since I thought it was an issue with the IDE not actually passing the options for the compiler and they just locked it and told me to piss off, that it was a compiler and/or code issue and therefore didn't belong there. And I can't find any forums for the compiler to ask on so here I am... anyway, on to the error:

C:\Users\Raezzor\Desktop\OPC\Ore Profit Cal\main.cpp|22|error: in C++98 'Veld' must be initialized by constructor, not by '{...}'|

Like I said I have -std=c++11 enabled for the GNU GCC compiler. I know C++11 was working with CB before as I had used it a while back but now I'm on a new comp and a new install of CB. I'd use a constructor, but using the brace initialization is so much simpler for my program since I'm using a number of structs in it. Here's my code so far (note, it's wildly incomplete since I just ran a test build to see if I had any issues with the new install and C++11 standards... and voila, I did. :p )

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

struct ORE
{
    float fOreValue = 0;
    int nTrit = 0;
    int nPyer = 0;
    int nMex = 0;
    int nIso = 0;
    int nNocx = 0;
    int nMega = 0;
    int nZyd = 0;
    int nMorph = 0;
};

int main()
{
    ORE Veld = {0, 415};
    ORE CVeld = {0, 436};
    ORE DVeld = {0, 457};
    ORE Scord = {0, 346, 173};
    ORE CScord = {0, 363, 182};
    ORE MScord = {0, 380, 190};
    ORE Pyro = {0, 351, 25, 50, 0, 5};
    ORE SPyro = {0, 368, 26, 53, 0, 5};
    ORE VPyro = {0, 385, 27, 55, 0, 5};
    ORE Plag = {0, 107, 213, 107};
    ORE APlag = {0, 112, 224, 112};
    ORE RPlag = {0, 117, 234, 117{;
    



    return 0;
}


Edit: Just had a thought, could this be related to the fact that I initialize data members to 0 in the struct declaration?

Edit 2: Tried this and the errors are gone but I get a lot of warnings about missing initializers for each struct... shouldn't the remaining data members of the struct not explicitly initialized in the lists be automatically initialized to 0?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

struct ORE
{
    float fOreValue;
    int nTrit;
    int nPyer;
    int nMex;
    int nIso;
    int nNocx;
    int nMega;
    int nZyd;
    int nMorph;
};

int main()
{
    ORE Veld = {0, 415};
    ORE CVeld = {0, 436};
    ORE DVeld = {0, 457};
    ORE Scord = {0, 346, 173};
    ORE CScord = {0, 363, 182};
    ORE MScord = {0, 380, 190};
    ORE Pyro = {0, 351, 25, 50, 0, 5};
    ORE SPyro = {0, 368, 26, 53, 0, 5};
    ORE VPyro = {0, 385, 27, 55, 0, 5};
    ORE Plag = {0, 107, 213, 107};
    ORE APlag = {0, 112, 224, 112};
    ORE RPlag = {0, 117, 234, 117};
    ORE Omber = {0, 85, 34, 0, 85};
    ORE SOmber = {0, 89, 36, 0, 89};
    ORE GOmber = {0, 94, 38, 0, 94};
    ORE Kernite = {0, 134, 0, 267, 134};
    ORE LKernite = {0, 140, 0, 281, 140};
    ORE FKernite = {0, 147, 0, 294, 147};




    return 0;
}
Last edited on
> shouldn't the remaining data members of the struct not explicitly initialized in the lists be automatically initialized to 0?

Yes. The remaining members are value-initialised. In this case (int), value-initialisation is initialisation with literal zero.
Topic archived. No new replies allowed.