Using arrays in classes

For some reason this won't work. Can someone please help me

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>

class Testclass
{
    int test[2];
};


int main()
{
    Testclass tst={{1,2}};
    return 0;
}


ERROR:
1
2
3
4
5
6
E:\CodeBlocks\Games\Console\Class_Test\main.cpp||In function 'int main()':|
E:\CodeBlocks\Games\Console\Class_Test\main.cpp|11|error: in C++98 'tst' must be initialized by constructor, not by '{...}'|
E:\CodeBlocks\Games\Console\Class_Test\main.cpp|11|error: no matching function for call to 'Testclass::Testclass(<brace-enclosed initializer list>)'|
E:\CodeBlocks\Games\Console\Class_Test\main.cpp|4|note: candidates are: Testclass::Testclass()|
E:\CodeBlocks\Games\Console\Class_Test\main.cpp|4|note:                 Testclass::Testclass(const Testclass&)|
||=== Build finished: 2 errors, 0 warnings ===|
You're trying to use C++11 initialization syntax, but you're using a C++98 compiler.
If you want to use that initialization syntax, use a current compiler.
Topic archived. No new replies allowed.