actually that behavior is PERFECTLY sensible, and i would be angry if it failed. two reasons:
1. C++ standard implies that a class is just a struct with private as its default scope. making class and struct not affect whether the array of data is an object or an area of data. since c++ is supposed to be somewhat backwards compatible with C.
2. according to the C++ standard, member functions that are not virtual are created staticly and called like normal functions with an added this parm. thus as long as the function is not virtual NO look up is required by the compiler so it can be handled at compile time instead of runtime.
example:
// C codestruct blah{ int x, y;};int blah_function(stuct blah* THIS){ printf("\n%d %d", THIS->x, THIS->y); return 0;}// would equal this in c++// C codestruct blah{ int x, y; function();};int blah::funtion(){ printf("\n%d %d", x, y); return 0;}
notice an similarities or other wierd things? like how its the same concept. classes where just an extension of structs by ALLOWING an implicitly called constructor and deconstror. if you dont require one, why should the compiler add the overhead of creating and calling one? makes no sense at all. furthermore, if you bother to check the disassembly you will notice the only difference between new and malloc is the function call to grab the memory. the "new" keyword prompts the compiler to insert a constructor/deconstructor and handle vtable stuff if needed. the actually call to "new" never does this at all.
furthermore please explain the difference in the following code, assuming that the standard makes exceptions based on atomic types like ints.
struct intStruct{ int x, y, z;};class intClass{public: int x, y, z;};int intArray[3];
from what you say the struct and class get constructors but the array does not. which makes me wonder, how reliable the standard is if you have stupid exceptions that make no sense. since in reality to the compiler all those are EXACTLY the same. granted access in the code will be slightly different since you have names for each of the members for the struct/class and not the array.
btw all the information was gathered from mulitple compiles of code and viewing the disassembly. whether its the standrd or not, really dont matter if its not implemented by compilers (especially popular ones like msvc++ AND gcc).
just for some more "nuggets" of information. gcc does not allow one to define a fucntion in a struct/class without a return type, since thats against the ansi c++ standard. msvc++ goes around this by assuming an int return type. yet gcc nor msvc care about the mallocing of a class and then calling the function. nor do they crash and burn. likewise i HIGHLY doubt that optimizations would EVER intefere with this. because if the compiler optimizes out the constructor and deconstructor whne NO optimizations are set and you are using debug which strives for easy debugging and not speed. i am pretty sure an optimizer wont screw that code up more (since you cant unless there is a MAJOR bug in the compiler, but then most function calls where you pass pointers would not work).
Saberman, i think where you are getting confused is by the fact that the ansi c++ standard allows c backwards combatiblity to a point. which REQUIRES that the behavior i have presented to you must exist. in fact ALL c++ code can be converted to c code (you probably know this), and it would be midly retarded to have implicit constructors in the c version for any struct that had no use for them.
the funniest thing you said though was how copying the .exe to another pc will somehow affect how its run. i dont quite understand how working compiled code will break on another system unless there is a hardware compatiblity issue, system file differences (ie different version of OS), or bad software that is running on the pc (ie 3rd party software that is buggy).
thankfully ppl like Magamei see my point, which is just because the standard says something, dont mean in reality thats how things work. the standard merely gives you a suggestion on how to implement things and how things should work in THEORY. in practice the compiler is free to make optimizations as long as it does not break code.