c 指针 java,C ++指针指向Java

I am a Java noob. I have been able to grasp the concept of converting C/C++ pointers into Java references and this has gone fairly smoothly.

I hit a piece of code that has pointers to pointers (ie **ptr). I need to dereference the pointer and change the value of the pointer it is pointing to (ie *ptr = &newthing;)

This seems alot tougher in java. Does anyone have any ideas on how to solve this issue? Quick google search turned up nothing.

Here's a code example in C++. I want to get something similar working in java but the ptr_to_ptr variable is a problem:

struct _coord

{

int x;

int y;

_coord * next_coordinate;

} coordinate_t;

coordinate_t buffer[100];

coordinate_t * head;

coordinate_t ** ptr_to_ptr;

if (wednesday)

{

ptr_to_ptr = &head;

}

else

{

ptr_to_ptr = &head->next_coordinate;

}

*ptr_to_ptr = &buffer[3]; // <<

解决方案

I'll answer my own question. I could not find any easy way to do a pointer to a pointer (reference to a reference) in java. So I refactored the code to use arrays of references, and array indices instead of pointers. I think this will work (it coded easily) but I have not tested it yet.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值