Location in memory of class object and member objects (C++)
Posted: Wed Jun 18, 2014 8:10 pm
In C++, when you create a class object which has member objects, are there any guarantees that the first member object starts at the same location in memory as the class object itself and that the member objects will be consecutive (i.e. a member object that is not the first is guaranteed to follow immediately after the previous memory object)?
I'm asking this, because I want an object that is stored in a struct to be able to access other members of that struct simply by using pointer arithmetic, so I am wondering if it is feasible and, if it is, guaranteed in the C++ standard.
I'm asking this, because I want an object that is stored in a struct to be able to access other members of that struct simply by using pointer arithmetic, so I am wondering if it is feasible and, if it is, guaranteed in the C++ standard.