结构"node"的迭代器不允许数据检索
Iterator for structure "node" is not allowing data retrieval
我正在努力解决问题。我有我们的常规节点结构和存储节点指针的列表。当我尝试使用迭代器来检索该列表时,我无法做到...
#include <list>
#include <iostream>
using namespace std;
struct node
{
int data;
node* next;
};
int main()
{
node * n = new node;
n->data = 3;
n->next = NULL;
list<node*> l;
l.push_front(n);
list<node*>::iterator myIt = l.begin();
cout << *myIt->data << endl; // <-- the compiler shows an error here "Member reference base type "node*" is not a structure or union"
}
也许我对迭代器的用法感到困惑。你能建议我解决方法吗?
欢呼!!
操作员优先级问题:使用cout << (*myIt)->data << endl;
cout << *myIt->data << endl;
您需要添加()
cout << (*myIt)->data << endl;
再见,
弗朗西斯
您实际上有点困惑,您需要做以下
cout << (*myIt)->data << endl;
您首先要取消指针,然后可以获取数据。
相关文章:
- 如何在Qt中从数据库中检索二进制数据?
- 两个垫子的 OpenCV 数据是相同的,但使用 Mat::at 检索时的值已损坏
- 打印从SQLite3数据库检索的数据C++与命令行中相同的方式
- 通过 host() 从 af::array 检索数据会导致错误的数据
- Winsock 数据不是从 IP 检索的,而是从普通 URL 检索的
- 在数据检索中使用矢量值
- 无法从 SQL Server 检索数据
- sd_journal_send发送二进制数据.如何使用日志检索数据?
- 无法在可视C++中检索资源文件数据
- 在 c++ 中使用指向对象的指针检索数据
- Getter 函数,用于在 2d 数组是类的数据成员时检索 2d 数组元素
- 从新实例的向量中检索数据返回 0
- 如何通过串行终端检索数据而不破坏其在 GNU ARM 嵌入式中的基本值?
- QNETWORK停止连接并检索数据
- 将 JSON 对象作为参数在 JNI 中传递给 CPP,并在 CPP 中检索 JSON 对象的数据
- 相机校准数据检索
- boost asio async_receive_from()在连续发送帧时缺少udp帧数据检索
- 数据检索和索引
- 结构"node"的迭代器不允许数据检索
- Matlab引擎数据检索失败