Skip to main content
gamedev.net
🔒 Locked

question about comiler generated default constructor.

Started by digitalfreak 1 reply 450+ views
Original Post
digitalfreak
digitalfreak
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.
Enigma
Enigma
I don't think there's any difference at all.
#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
chollida1
chollida1
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
CheersChris

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.