構造体ポインタのリストからメンバにアクセスできない
Posted: 2010年10月24日(日) 12:03
#include <iostream>
#include <list>
using namespace std;
struct Element
{
int i;
};
int main()
{
list<Element*> l;
list<Element*>::iterator it;
Element e = {3};
l.push_front(&e);
it = l.begin();
cout << *it->i << endl;
return 0;
}
これをコンパイルしようとすると、"-> か ->* の左には構造体のポインタが必要"とエラーが出てコンパイルできません。
どこがいけないのでしょうか。
#include <list>
using namespace std;
struct Element
{
int i;
};
int main()
{
list<Element*> l;
list<Element*>::iterator it;
Element e = {3};
l.push_front(&e);
it = l.begin();
cout << *it->i << endl;
return 0;
}
これをコンパイルしようとすると、"-> か ->* の左には構造体のポインタが必要"とエラーが出てコンパイルできません。
どこがいけないのでしょうか。