如何将指针作为双指针传递给类的指针属性?
我不知道如何正确传递这个双指针......我尝试过的都不起作用......
class myClass{
MyClass *attribClass;
}
void derp(MyClass **myA) {
// recursively calls down classes....
derp(&(myA->attribClass)); // what am i doing wrong?
}
int main() {
MyClass *myClass = new MyClass;
myClass.attribClass = *whatever code to initialize a long linked list of MyClass's*;
derp(&myClass);
}
I cant figure out how to properly pass this double pointer.... nothing i've tried works...
class myClass{
MyClass *attribClass;
}
void derp(MyClass **myA) {
// recursively calls down classes....
derp(&(myA->attribClass)); // what am i doing wrong?
}
int main() {
MyClass *myClass = new MyClass;
myClass.attribClass = *whatever code to initialize a long linked list of MyClass's*;
derp(&myClass);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有几个问题:
在最后一个问题中,您需要在访问
attribClass
之前引用myA
一次。There's several issues:
And in the last one, you need to deference
myA
once before you accessattribClass
.myA
是一个指向指针的指针,因此您需要取消引用它以获取可以使用->
的指针,所以:应该
我 假设您需要更改/设置指针的值。如果你不是,那么你可能不应该在这里使用双指针。
myA
is a pointer to a pointer, so you need to dereference it to get a pointer which you can use->
with, so:Should be
I'm assuming you need to change/set the value of the pointer. If you aren't you probably shouldn't use a double pointer here.
您需要对
myA
进行额外的取消引用,其类型为MyClass **
(不仅仅是MyClass *
):You need an extra dereference on
myA
, which is of typeMyClass **
(not simplyMyClass *
):