Does anyone use netbeans for c++? I can't figure out how to make it show me compiler warnings (they show for a split second, but the terminal clears when the program runs)
quick question : if i have "float x [];" inside a class of a header file how can i do something like this in the Ctor of the cpp file : x [] = {1, 2, 3}; ?
Array creation and initialization
As with any other kind of C++ object, arrays can be stored either directly in named variables (then the size must be a compile-time constant; C++ does not support VLAs), or they can be stored anonymously on the heap and accessed indirectly via pointers (only the...
quick question : if i have "float x [];" inside a class of a header file how can i do something like this in the Ctor of the cpp file : x [] = {1, 2, 3}; ?
@Shago You can't. float x []; is not a legal member of a class. You are probably using a gcc extension to make it compile, but it still doesn't work the way you want it to.
There are some C-tricks with over-allocating, but it is difficult and error-prone to pull off. Use a std::vector<float> instead.
Is there some built in mechanism in g++ that prevents the trivial code in this question to go out of bounds? VC++ result goes out of bounds and prints garbage.
@Ron Undefined behavior is undefined. There happened to be a 0 at the end of that array. Some debuggers initialize the stack with all 0s, which is not actually helpful.
Apparently when compiled on my local machine under Linux it also exhibits UB. I was under the impression the Coliru and local results should be identical.