3
class B {
};

class A {
    A(B& b):_b(b)  
    B& _b;
};

int main() {
    B b;
    A a(b);
    char* x = reinterpret_cast<char*>(&a);
}                               

I'm creating a hash function based on the byte values of the objects. I want to know wether the bytes of object a will hold b or will they hold a reference (pointer)?

Paul R
  • 208,748
  • 37
  • 389
  • 560
mkmostafa
  • 3,071
  • 2
  • 18
  • 47
  • See [this list of recommended books on C++](http://stackoverflow.com/q/388242/253056). – Paul R Aug 09 '16 at 09:13
  • Objects don't have byte values. Two different byte arrays may well represent the same object value. How references are represented is implementation defined. – n. m. could be an AI Aug 09 '16 at 09:16

1 Answers1

1

As you declared A::_b as a reference, it will "hold" a reference. Thus the object a does not contain the data of b if you examine a byte-wise.


By the way you forgot to use the address-of operator in your cast.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621