开发者

var DB*; in C++

开发者 https://www.devze.com 2023-01-16 07:12 出处:网络
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\"):

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 n开发者_StackOverflowame 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?


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!).


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...


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号