【发布时间】:2013-04-02 03:50:24
【问题描述】:
这是一段简单的代码,它给了我错误的输出,但我不知道为什么。
#include <iostream>
#include <list>
using namespace std;
void main(){
list<int*> l;
int x = 7;
int* y = &x;
//it works if I put list<int*> l; on this line instead.
l.push_back(y);
cout << **l.end() << endl; // not 7
}
我该如何解决?
【问题讨论】:
-
void main是非标准的,l.end()并没有“指向”任何地方,特别是在解除引用的意义上。