STL 结构体访问问题

#include"stdafx.h"#include"iostream"#include"list"#include"iterator"usingnamespacestd... #include "stdafx.h"
#include "iostream"
#include "list"
#include "iterator"
using namespace std;
struct pl
{
int x;
int y;
};
class pla
{
public:
int x;
int y;
};
list<pla> il;
list<pla>::iterator it;
int _tmain(int argc, _TCHAR* argv[])
{

for(int i=0;i<10;i++)
{
pl p1;
p1.x=i;
p1.y=i*10;
il.push_back(p1);
}

for(it=il.begin();it!=il.end();it++)
{
int x,y;
x=*it->x; //error C2100: 非法的间接寻址
y=*it->y; //error C2100: 非法的间接寻址
cout<<x<<endl;
}
return 0;
}
无论是结构体还是类都是这错误,如果我写的方向有问题请指点下该怎么写
展开
 我来答
vbtraz
2011-08-22 · TA获得超过5532个赞
知道大有可为答主
回答量:4152
采纳率:0%
帮助的人:4510万
展开全部
it是 list<pla>::iterator 语法上相当于是个 *pla ,所以访问类内容就 it->x 和 it->y , 前面写什么*就错了
网易云信
2023-12-06 广告
网易云信提供一站式的 1 对 1 UIKit 组件库,可以更快地搭建 1 对 1 社交平台,能够快速实现音视频呼叫、音视频通话、1对1消息发送、美颜和礼物功能,直接可以复用我们的组件源码就可以了。优势:1、全套1对1 UI组件,接入更快;2... 点击进入详情页
本回答由网易云信提供
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式