-2

Getting warning while using below code:

warning: extended initializer lists only available with std c++ 11

struct test{
 int a;
 int b;
};

//Previously const test atest[] = { {2,3} {4,5} };
const test atest[] = { {2,3} , {4,5} };

How can I remove this? I tried with solution, but it didn't work.

5
  • 2
    Did you intentionally tag this as c?
    – Bathsheba
    Aug 13, 2014 at 8:12
  • I changed it to C++ now..
    – kapilddit
    Aug 13, 2014 at 8:34
  • 3
    What compiler are you using? What version? What options are you using? I can't reproduce this for your code, are you sure that's what you're compiling? If you are trying to use C++11 then you need to use -std=c++11 or -std=gnu++11 Aug 13, 2014 at 8:55
  • What does the compiler generate when you use const test atest[] = {2,3,4,5};?
    – Niall
    Aug 13, 2014 at 9:36
  • I am using MGC 1.8 compiler. Mentor Graphics Compiler.
    – kapilddit
    Aug 13, 2014 at 13:08

1 Answer 1

4
const test atest[] = { {2,3}, {4,5} };

You forget the comma, and in C you need the struct keyword if test is not typedefed:

const struct test atest[] = { {2,3}, {4,5} };
2

Not the answer you're looking for? Browse other questions tagged or ask your own question.