Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
(iphone)如何访问c++;班 我有一个CGRCt变量的C++类,当访问它时,我得到了StEnt错误。 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; };_Iphone_C++_Objective C - Fatal编程技术网

(iphone)如何访问c++;班 我有一个CGRCt变量的C++类,当访问它时,我得到了StEnt错误。 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; };

(iphone)如何访问c++;班 我有一个CGRCt变量的C++类,当访问它时,我得到了StEnt错误。 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; };,iphone,c++,objective-c,Iphone,C++,Objective C,我在做什么 CGRect rect = childPtr->GetRect(); 从对象c代码和它的故障中分离。 我在调用之前打印了*childPtr,rect看起来与预期的数据值一致 int index = childPtr->GetIndex(); 来自同一个对象c代码(*.mm),但效果很好 你知道我为什么会犯错误吗? 多谢各位 编辑- 这与虚拟函数有关 (gdb)p单件->GetRect() 程序接收到信号EXC_访问错误,无法访问内存。 原因:地址0x00

我在做什么

 CGRect rect = childPtr->GetRect();   
从对象c代码和它的故障中分离。
我在调用之前打印了*childPtr,rect看起来与预期的数据值一致

int index = childPtr->GetIndex(); 
来自同一个对象c代码(*.mm),但效果很好

你知道我为什么会犯错误吗?
多谢各位

  • 编辑-
这与虚拟函数有关

(gdb)p单件->GetRect()

程序接收到信号EXC_访问错误,无法访问内存。 原因:地址0x00000001处的内核保护失败 0x00000001英寸??() 无法访问地址0x1处的内存 正在调试的程序在从GDB调用的函数中发出信号。 GDB保留在接收信号的帧中。 若要更改此行为,请使用“将取消签名设置为打开” 将放弃对包含函数(在0x1处)的表达式的求值。 (gdb)


不知何故,函数没有正确编译?

在目标C中获得rect变量 你这样做吗

int indexX=rect.origin.x

int indexY=rect.origin.y


等等

看看你给我们的代码,它似乎应该能工作。子项应该从父项派生吗?GetRect()是父函数中的虚拟函数吗?如果是的话,它的实现是什么?childPtr是孩子还是家长?我认为我们需要更多的上下文。有child1,child2和yes需要从父母那里派生出来。GetRect()在父级是纯虚拟的。childPtr是父级*的类型。让我感到困惑的是,据我所知,CGRect只是c结构。我还尝试了将ptr强制转换为Child*在callI发现它与CGRect无关之前,所有虚拟函数调用都会导致segfaults。发现问题了。ptr在呼叫前已被删除。。我真傻。谢谢你!