【发布时间】:2016-01-10 11:37:46
【问题描述】:
您好,我想创建列表结构,但我不想使用结构,但我想使用对象。我是新手,当我执行此代码时它不起作用。
#include<stdlib.h>
#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
class List {
public:
int id;
List* next = NULL;
List* prev = NULL;;
static List create(int value, int id = 0){
List list;
list.value = value;
list.next = NULL;
list.prev = NULL;
list.id = id;
return list;
}
void add(int value){
this->next = &List::create(value, this->id + 1);
}
void show(){
cout << "#" << this->id << endl << " " << this->value << endl;
if (this->next != NULL){
cout << (*this->next).id;
}
else{
cout << "NE ESTAS";
}
}
protected:
int value;
};
int main(void){
cout << "Hello, It's a simple Object Lists program" << endl << endl;
List head = List::create(1);
head.add(2);
head.show();
getch();
return 0;
}
当我尝试检查list.next 地址在create() 方法和show() 中是否相等但值不同时。我做错了什么?
【问题讨论】: