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
  • 202,568
  • 34
  • 375
  • 539
mkmostafa
  • 2,863
  • 2
  • 16
  • 44

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
  • 380,411
  • 33
  • 383
  • 585