gerstla
gerstla

Reputation: 597

c++ pointer assignment in 64bit

I am trying something like this

//A.h
class P;

class A
{
  A(P* pp) { p = pp; }
  P* p;
};
//B.h
#include "P.h"

class B : public A
{
   B(A* aa);
};
//B.cpp
B::B(P* pp) : A(pp)
{}

the problem is that when for example

pp = 0x00000000024af3f0 

but after the assignment

p = 0x024af3f0cdcdcdcd

this happens only in 64bit. also if I dont use the forward declaration of P there is no problem. and also if I do p = pp; in B's constructor there is no problem.

Upvotes: 0

Views: 254

Answers (1)

TonyK
TonyK

Reputation: 17114

This can happen if you forget to re-compile one of the source files after adding data to class A. The offset of p changes (in your case, by four bytes), but only one of the source files knows about it. Recompile everything and try again.

Upvotes: 4

Related Questions