(iphone) How to access CGRect member variable inside c++ class?

Posted by Eugene on Stack Overflow See other posts from Stack Overflow or by Eugene
Published on 2010-12-22T14:38:38Z Indexed on 2010/12/23 3:53 UTC
Read the original article Hit count: 152

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about c++