question about comiler generated default constructor.
what's the difference between an explicitly defined empty constructor(no arg and empty body) and a comiler generated default constructor?
from section 10.4.2 (p243) of the c++ programming language(special edition), it seems the latter one doesn't initialize members of build-in types while the former one does (from my experiment).
is that correct.
I don't think there's any difference at all.
Enigma
#include <iostream>class DefaultConstructor{ public: int i;};class EmptyConstructor{ public: EmptyConstructor() { } int i;};void fillStack(){ int someVar = 0xF8E9DACB;}void makeDefaultConstructedObject(){ // make sure the stack is filled with messy values fillStack(); DefaultConstructor dc; std::cout << dc.i << '\n';}void makeEmptyConstructedObject(){ // make sure the stack is filled with messy values fillStack(); EmptyConstructor ec; std::cout << ec.i << '\n';}int main(){ makeDefaultConstructedObject(); makeEmptyConstructedObject();}
Enigma
Did you test this in releas or debug. When you launch your app from the debugger( in my case vs.net) the debugger will init vars to 0, even in release.
If you launch it outside the debugger then it won't init the vars in release
Try using logging to see what happens in release outside of the debugger.
Cheers
Chris
If you launch it outside the debugger then it won't init the vars in release
Try using logging to see what happens in release outside of the debugger.
Cheers
Chris
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement