c++ - Why is it necessary to do a rebuild after adding a new member variable to a class? -


this morning, in visual studio 2005, tried adding new private member variable class , found giving me sorts of weird segmentation faults , like. when went debug mode, found debugger didn't see new member variable, , giving me strange behavior.

it required "rebuild all" in order program working again (and debugger see new member variables had made). why necessary rebuild all? why doing regular build insufficient?

i solved problem, feel understanding build process better me in future. let me know if there's more information need.

thanks in advance!

when add or remove members of class change memory layout of object. if don't recompile breaking odr rule, , segmentation faults effect of that.

as why happens, old code might acquiring memory old size, , passing object (without new member) new code access beyond end of allocated memory access new variable. note access specifier not affect @ all, if private class member functions ones accessing fields.

if did not add field end, rather middle of object, same effect seen while accessing fields laid out compiler in higher memory addresses.

the fact needed use rebuild all feature indication dependencies of project not correctly configured, , should fix possible. having right dependencies force compiler rebuilding when needed, , mean less useless debugging hours.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -