i think you just make a mistake when you declare
static int array[size] ;
because std c++ doesn't support "dynamic" declare , you know size is not a
const number, so this will generate a mistake. and i compile it in dev-c++
4.9.8.0 with winme,
it just appear "4 D:\source code\stl_c++\statictest.h
size of member `array' is not constant"
so if you want to achive this ,i think the best way is to use stl: vector.
"Rahul Joshi" <ru*****@students.uiuc.edu>
??????:Pi*************************************@ux7 .cso.uiuc.edu...
Hi,
I want to create a static array whose size is also a const
member of the class. Something like:
// A.h
class A {
private:
static int size = 0;
static int array[size];
};
Then I need to define the static array in A.cpp like:
int A::array[A::size];
However, the compiler complains that A::size is a private
and cannot be accessed. So how can I define such a static
array without making the size of the array public ?
Thanks,
Rahul