gpt4 book ai didi

c++ - 将指针设置为一个值加上一个单独的值

转载 作者:行者123 更新时间:2023-11-30 00:56:40 26 4
gpt4 key购买 nike

是否可以将指针设置为一个值但有轻微的偏移。

类似于:

m_NewPosition = &m_Position + Vector3(0,0,10);

所以 NewPosition 的值是实际位置加上 10 infront。

使用 C++。

最佳答案

如果指针指向数组,则只能对指针使用偏移量。

所以如果你有 char arr[10]; 并且你用一些东西填充它,那么你可以做 char *p = arr + calc_offset();,只要你不超出数组的范围。

来自 C++ 标准:

If both the pointer operand and the result point to elements of the same array object, or one past the last element of the array object, the evaluation shall not produce an overflow; otherwise, the behavior is undefined.

关于c++ - 将指针设置为一个值加上一个单独的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9604551/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com