【发布时间】:2014-08-31 09:20:38
【问题描述】:
我正在尝试将对象添加到链接列表。我的程序的想法是制作一个学生信息系统。在这个学生信息系统中,当有一个新的学生条目时,将创建一个新的类对象,该对象将作为链表中新节点的信息。换句话说,对象将是链表节点的信息字段。我试过这个程序,但出错了。
#include<iostream.h>
class result
{
int age;
char name[30];
float marks;
public:
void ret(int a, float m)
{
age = a;
marks = m;
}
};
struct node
{
result info;
struct node *next;
};
void main()
{
struct node *h, *t;
int g;
float ma;
cout<<"Enter age , name , marks\n";
cin>>g;
cin>>ma;
result ob;
h = NULL;
t = new node;
t->info = ob.ret(g,ma);
t->next = NULL;
h = t;
cout<<t->info;
}
错误是:
1) 不允许的类型 2)非法结构操作
【问题讨论】:
-
错误发生在哪里?
标签: c++ object linked-list