How to declare dynamic arrays????

Hello, I am not sure how I should go about declaring a class array with a pointer. Should I do something like this:

1
2
3
4
5
6
7
8
9
10
11
12
//Fish being a class
//Initializing with default values so [] doesn't give error
Fish fishdata []={Fish("a",0,0)},
     fishptr*=fishdata;

int num;


cout<<"Get whatever input: ";
cin>>num;

fishptr=new Fish[num];


or is it acceptable/better to just make it into a pointer from the start, like this:

1
2
3
4
5
6
7
8
Fish *fishdata;

int num;

cout<<"Get whatever input: ";
cin>>num;

fishdata=new Fish[num];


By the end of the program I am going to write the data into a file anyway, so what is better to do?
first will give you an error if you didn't overload operator *= for youir Fish class (you are not declaring pointer here)

Second example is always preferable.
Thank you just needed to make sure
Topic archived. No new replies allowed.