查找由链接列表链接的数据的各个地址.C++
Finding the individual addresses of data linked by a linked list. C++
我在从链表中的项目中取回一些地址时遇到了一些问题。与在for循环开始时创建和初始化的迭代器地址不同,我希望获得位于列表中的实际数据的地址。如果不创建我自己的列表实现,这可能吗?这是我得到的代码块,但很明显,它没有按照我想要的方式工作
int j = 0;
testIntList.resize(100);
for (list<int>::iterator i = testIntList.begin(); i != testIntList.end(); ++i) {
*i = j*j;
int * k = &(*i);
cout << "the value of the iterator is " << *i << " and the address of the iterator is " << &i << "and the address of the pointer is " << *k << endl;
j++;
}
我以这种方式使用k来尝试获取迭代器值的地址在内存中的实际指针。如有任何帮助,我们将不胜感激。
i
是迭代器,因此&i
将是迭代程序的地址,而不是您想要的地址。现在,您知道*i
是迭代器指向的对象,所以该对象的地址是&*i
。这就是您在k
中输入的内容。只需打印出k
即可。
cout << "the value of the iterator is " << *i
<< " and the address of the iterator is " << &i
<< " and the address of the pointer is " << k << endl;
相关文章:
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- CMake-按正确顺序将项目与C运行时对象文件链接
- 从链接列表c++中删除一个项目
- 有根的二进制搜索树.保留与其父级的链接
- 读取文件的最后一行并输入到链接列表时出错
- 静态数据成员的问题-修复链接错误会导致编译器错误
- node-gyp 在 macOS 上未正确链接库
- 链接列表和数组中的C 内存地址
- 链接列表错误 - 为什么头和尾引用指向相同地址
- C 错误:0x00934ABB(链接列表,地址簿)的未手动异常
- 如何将GCC链接器固定地址添加到链接文件中
- 我可以在编译期间从 gcc 获取单例的地址或链接时吗?
- 存储链接列表节点地址
- 链接器错误:未定义的引用/错误的重新定位地址/ld返回1个出口
- 链接器用内存地址替换符号引用
- 未定义的引用,但(动态)库被链接.(可能是坏的重定位地址错误)
- 链接列表中的指针地址不会改变
- 查找由链接列表链接的数据的各个地址.C++
- 复制构造函数双链接列表中的头节点和尾节点的地址不正确
- GCC链接器描述文件强制符号位于特定地址