dynamic array of constants

Hi all,

I would like to define a dynamic array of constant objects - so the array size is not known at compile time. How am I able to acheive this ?

Thanks
Use Vector instead.
you need a double pointer

1
2
3
4
5
6
7
8
9
classname **mydata;


mydata = new classname *[size];

for(int i = 0; i < size; i++
{
    mydata[i] = NULL;
}


thats what u need to do what u are asking

a classname pointer to an array of pointers to your class
Last edited on
Thanks, but I think I maybe did not express it right.

In my program, I would like to read a table of integers from a file, store it in an array and ensure that they would stay unchanged from then on (by using const).

So is there a way to define a:
const* int

So that when I use new, I can assign them all once ?

Thanks
1
2
3
4
5
6
7
8
9
10
11
12
13
int const* readConstants() ;

int const * const myConstants = readConstants();


int const * readConstants()
{
     int * buffer = new int[/**/] ;
   
      // ...

     return buffer ;
}


The same thing can be done with a vector.
Last edited on
Thank you !
That was really helpful.
Topic archived. No new replies allowed.