Consider these two cases :
struct customType
{
dataType1 var1;
dataType2 var2;
dataType3 var3;
} ;
customType instance1;
// Assume var1, var2 and var3 were initialized to some valid values.
customType * instance2 = &instance1;
dataType1 firstMemberInsideStruct = (dataType1)(*instance2);
class CustomType
{
public:
dataType1 member1;
dataType2 member2;
retrunType1 memberFunction1();
private:
dataType3 member3;
dataType4 member4;
retrunType2 memberFunction2();
};
customType object;
// Assume member1, member2, member3 and member4 were initialized to some valid values.
customType *pointerToAnObject = &object ;
dataType1 firstMemberInTheObject = (dataType1) (*pointerToAnObject);
Is it always safe to do this ?
I want to know if standard specifies any order of storage among -
- The elements inside a C structure.
- Data members inside an object of a C++ class.
*(classInstancepointer->memberpointer)(approximately has been a while) to access the data, by exchanging the instance pointer you can access the data in different Instances. - ted&instance.memberis to set up the pointer, yezx i forgot to put that. But I think I can racall something likeauto p=&class::memberandauto inst=&class()to be used ass member and instance pointer in the code I mentioned above. In your case it looks like you are already getting a bound object pointer which i think difers slightly from the desired result. - ted