Skip to main content
gamedev.net
๐Ÿ”’ Locked

Does variable order matter when saving an object?

Started by Roof Top Pew Wee Mar 20, 2003 at 4:29 PM 1 replies 100+ views
Original Post
Roof Top Pew Wee
Roof Top Pew Wee
Say I have a class: class a {public: int m_int; float m_float; } And during my program I save the file: a myAObject; ofstream outfile("filename.ext", ios::binary); outfile.write(reinterpret_cast(& (myAObject)), sizeof(a )); But what if later I change my code to be: class a {public: float m_float; int m_int; } Now the float is first. If I tried to load that object that was saved before, would it load weird because it thinks the float is saved first, then the int? --Vic--
sjelkjd
sjelkjd
Note that your reinterpret cast won''t work if your object is polymorphic, contains pointers, or contains objects that are polymorphic, contain pointers, or ...

Topic Locked

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

Sign in to reply to this topic.