tags:

views:

58

answers:

3

My professor sent back a short email:

int x = 100;
var HT*;
HT = new int[x];

Firstly: Compiling the code (with other stuff around it to make it "work"): error: 'var' does not name a type.

Second: This is for hash tables. Apparently this is the way to create an array of variable size according to the ANSI standard (G++ has extensions that we can't use or he'll shoot us).

Any ideas?

A: 

change the var to an int which should get rid of the first error.

VoodooChild
@Voodoo, not sufficient: the star is also in the wrong place, _after_ the identifier being declared and defined, while it should be _before_ it (see my answer).
Alex Martelli
@Alex: good catch; I read the code without seeing that .
Cedric H.
+3  A: 

var HT* is not valid C++ syntax (looks C#-inspired to me;-) -- int *HT is how, in C++, you declare HT to be a pointer to integer (which can hold the result of an array-new -- you'll have to remember to use delete[] and not plain delete when you're done, though!).

Alex Martelli
+1  A: 

It should be auto which is the equivalent of var in C#. But I think, if your professor does not allow usage of std::vector, he or she will neither allow usage of std::array nor the c++0x code elements. To my knowledge there is no var keyword wheter present nor intended in standard c++. There is one in C++/CLI, but after what I have red, if you just mention this acronym your professor gets a heart attack...

paul_71