我一直在想这个。
#include <iostream>
#include <vector>
int main() {
std::vector<int> a;
std::vector<int *> b;
a.push_back(13);
b.push_back(&a.back());
a.push_back(24);
b.push_back(&a.back());
for (std::vector<int>::iterator it = a.begin(); it != a.end(); ++it)
std::cout << *it << " ";
std::cout << "\n";
for (std::vector<int *>::iterator it = b.begin(); it != b.end(); ++it)
std::cout << *(*it) << " ";
std::cout << "\n";
return 0;
}
输出:
13 24
16712910 24
我真的很想知道,为什么两条输出线都不匹配。我在这里想念什么?我用 gcc 4.6.3 编译了这个