tags:

views:

69

answers:

3
int* HT;
int HTc = 500;
HT = new int[HTc] = {-1}; //Fill array with -1

I get the warning: extended initializer lists only available with -std=c++0x or =std=gnu++0x

I'll assume this means it isn't compatible with the ANSI standard, which my prof. is nuts for. How else would I do this though?

+2  A: 

I'm not sure this would work the way you want even if you used the recommended options - wouldn't it initialize the first array element to -1 and the rest to 0?

Just loop through all the elements and set them individually.

Mark Ransom
+6  A: 

Use std::fill. It would be better to use a std::vector than a c style array, but just for demonstration:

#include <algorithm>

int HTc = 500;
int HT[] = new int[HTc];
std::fill(HT, HT+HTc, -1);
// ...
delete[] HT;
Todd Gardner
+2  A: 

Unless you have some truly outstanding reason to do otherwise, the preferred method would be to not only use a vector, but also specify the initial value when you invoke the ctor: std::vector<int> HT(500, -1);

Jerry Coffin
His professor doesn't allow it, apparently. How do terrible programmers end up teaching?
GMan
I guess it fits the old line about "those who can, do; those who can't, teach; those who can't teach, teach PE" -- only in this case, they apparently teach programming. Which, in turn, brings to mind another old line, to the effect that: "Free verse is the most difficult poetry to write acceptably -- and therefore the most often attempted by those who cannot write any poetry acceptably."
Jerry Coffin