[問題] vector初始化的問題
#include <vector>
#include <iostream>
using namespace std;
class Bin;
vector<Bin> *v;
struct Bin {
int *glass;
Bin():glass(new int(0)) {}
};
int main() {
v = new vector<Bin>(2);
*(v->at(0).glass) = 9;
cout << *(v->at(1).glass) << endl;
}
為什麼output會是9而不是0?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.91.181
推
02/02 13:35, , 1F
02/02 13:35, 1F
→
02/02 13:36, , 2F
02/02 13:36, 2F
→
02/02 15:49, , 3F
02/02 15:49, 3F
推
02/02 17:08, , 4F
02/02 17:08, 4F
推
02/02 17:10, , 5F
02/02 17:10, 5F
推
02/02 18:01, , 6F
02/02 18:01, 6F
→
02/02 18:07, , 7F
02/02 18:07, 7F
推
02/02 18:57, , 8F
02/02 18:57, 8F
→
02/02 19:36, , 9F
02/02 19:36, 9F
→
02/02 19:37, , 10F
02/02 19:37, 10F
→
02/02 19:39, , 11F
02/02 19:39, 11F
推
02/02 20:08, , 12F
02/02 20:08, 12F
→
02/02 20:12, , 13F
02/02 20:12, 13F
→
02/02 20:13, , 14F
02/02 20:13, 14F
→
02/02 20:13, , 15F
02/02 20:13, 15F
→
02/02 20:14, , 16F
02/02 20:14, 16F
→
02/02 20:15, , 17F
02/02 20:15, 17F
→
02/02 20:16, , 18F
02/02 20:16, 18F
推
02/02 20:17, , 19F
02/02 20:17, 19F
推
02/02 20:19, , 20F
02/02 20:19, 20F
→
02/02 20:19, , 21F
02/02 20:19, 21F
→
02/02 20:19, , 22F
02/02 20:19, 22F
→
02/02 20:19, , 23F
02/02 20:19, 23F
→
02/02 20:19, , 24F
02/02 20:19, 24F
→
02/02 20:19, , 25F
02/02 20:19, 25F
→
02/02 20:19, , 26F
02/02 20:19, 26F
→
02/02 20:19, , 27F
02/02 20:19, 27F
推
02/02 20:21, , 28F
02/02 20:21, 28F
推
02/02 21:00, , 29F
02/02 21:00, 29F
討論串 (同標題文章)
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章