我正在尝试编写复数的动态链接列表。基本上:我有一个类list
,其中包含一个number
包含 class的结构complex
。盒中盒中盒。我在引用复数本身时遇到问题(我只有添加节点的函数。到目前为止我的代码:
复杂的.h
class complex
{
public:
float r;
float i;
};
列表.h
#include "complex.h"
class list
{
public:
typedef struct number
{
complex a;
struct number *next;
}number;
number *number;
public:
void add(number* number,complex b);
list();
~list();
};
list.cpp(包含函数添加,不起作用)
void list::add(number* number, complex b)
{
number *newo=new number;
while (number->next != NULL)
{
number = number->next;
}
newo = malloc (sizeof(number));
newo->a::r = b::r;
newo->a::i = b::i;
newo->next = NULL;
number->next = newo;
}
感谢帮助 ;)