class Try {
const int no = 5;
int arr[no];
};
Here is a simple class , but I get this compilation error. no
is constant so I thought it should not be the problem.
arr
must have the same size in all instances of your class. no
is const but that only means it never changes after an instance is created. It doesn't mean that it is the same for all instances all the time. For example, no
can be set in the initializer list of the constructor
Foo::Foo(int size) : no(size)
{}
For this reason, unless you make no
static, you can't use it as array size because that would imply potentially differently sized arrays in each instance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With