I do not understand anything. Foo() allowed, even if it makes no sense ... I tried changing the struct to class and tried diff for the generated exe, and they turned out to be the same, which means that a class without a method is similar to a structure from a practical and "efficient" point of view .
But : if you use only one alternative, it doesn’t matter when storing a struct or class , it happens that new Foo and new Foo() give executable files that are different! (At least using g ++) Ie
struct Foo {int i; double d; }
int main () {Foo * f1 = new Foo; delete f1; }
compiled to something other than
struct Foo {int i; double d; }
int main () {Foo * f1 = new Foo (); delete f1; }
and the same thing happens with class instead of struct . To find out what the difference is, we need to look at the generated code ... and know whether it is g ++ idiocy or not, I should try another compiler, but I only have gcc and no time to parse asm g ++ output ...
In any case, from the "functional" (practical) point of view, this is one and the same.
Add
In the end, it’s always better to know or do a deeper study of some common human problems on Q / A sites ... the only difference is in the code generated by the g ++ in () and no () cases,
movl $ 0, (% eax)
fldz
fstpl 4 (% eax)
which is a fragment that initializes the value of the 0 / 0.0 int and double structures ... so Seymour knows this better (but I could detect it without knowing if I looked at asm first!)
ShinTakezou Jun 01 '10 at 16:50 2010-06-01 16:50
source share