小编use*_*015的帖子

为什么动态创建的对象与对象的大小相差两倍?

我编写了代码来创建动态创建对象的链接列表:

#include <iostream>
using namespace std;

struct X {
  int i;
  X* x;
};

void birth(X* head, int quant){
  X* x = head;
  for(int i=0;i<quant-1;i++){
    x->i = i+1;
    x->x = new X;
    x = x->x;
  }
  x->i = quant;
  x->x = 0;
}

void kill(X* x){
  X* next;
  while(1==1){
    cout << x->i << endl;
    cout << (long)x << endl;
    next = x->x;
    delete x;
    if(next == 0){
      break;
    } else {
      x = next;
    }
  }
}

int main(){
  cout …
Run Code Online (Sandbox Code Playgroud)

c++ heap-memory

3
推荐指数
1
解决办法
125
查看次数

标签 统计

c++ ×1

heap-memory ×1