I need to create two classes, and inside one of the classes I must have an array of objects defined by the other class. The size of the array is supposed to be detirmined by a variable.
Something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
#include <iostream>
class Grault
{
//...
};
class Corge
{
int size = 10;
Grault waldo[size];
//...
};
|
Error: ISO C++ forbids initialization of member 'size'
Error: making 'size' static
Error: ISO C++ forbids in-class initialization of non-const static member 'size'
Error: array bound is not an integer constant
I tried changing it to:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
#include <iostream>
class Grault
{
//...
};
class Corge
{
const int SIZE = 10;
Grault waldo[SIZE];
//...
};
|
Error: ISO C++ forbids initialization of member 'SIZE'
Error: making 'SIZE' static
I know that if I place the
const int SIZE = 10;
outside the class scope, it will work. But in the directive its placed inside the scope. Cant change that. But how do I make it work?