(iphone) How to access CGRect member variable inside c++ class?
- by Eugene
i have a c++ class with CGrect variable and i'm getting segfault when trying to access it.
class Parent
{
//with some virtual functions/dtors
};
class Child
{
public:
void SetRect(CGRect rect) { mRect = rect; }
CGRect GetRect() { return mRect; }
int GetIndex() { return mIndex; }
private:
CGRect mRect;
int mIndex;
};
i'm doing
CGRect rect = childPtr->GetRect();
from object c code and it segfaults.
I printed *childPtr just before the call and rect looks fine with intended data value.
int index = childPtr->GetIndex();
from same object c code(*.mm), works fine though.
Any idea why I'm getting segfaults?
Thank you
edit -
It's got something to do with virtual functions.
(gdb) p singlePuzzlePiece-GetRect()
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0x00000001
0x00000001 in ?? ()
Cannot access memory at address 0x1
The program being debugged was signaled while in a function called from GDB.
GDB remains in the frame where the signal was received.
To change this behavior use "set unwindonsignal on"
Evaluation of the expression containing the function (at 0x1) will be abandoned.
(gdb)
Somehow, the function is not properly compiled?