#include "MyArrayList.h"
MyArrayList::MyArrayList()
{
size = 0;
}
NODE* MyArrayList::list_create(void *data)
{
NODE *node;
if(!(node=malloc(sizeof(NODE))))
return (NODE*)NULL;
node->data=data;
node->next=NULL;
return node;
}
NODE *MyArrayList::list_add(NODE *node, void *data)
{
NODE *newnode;
newnode=list_create(data);
newnode->next = node->next;
node->next = newnode;
return newnode;
}在……上面
NODE* MyArrayList::list_create(void *data)
{
NODE *MyArrayList::list_add(NODE *node, void *data)
{myarraylist.cpp(8):错误C2143:语法错误:'*‘前缺少';’
myarraylist.cpp(8):错误C4430:缺少类型说明符-假定为int。注意: C++不支持default-int
myarraylist.cpp(8):错误数据:‘C2065’:未声明的标识符
myarraylist.cpp(8):错误C2761:'MyArrayList::NODE *MyArrayList::list_create(*MyArrayList::list_create *)‘:不允许成员函数重新声明
myarraylist.cpp(8):致命错误C1903:无法从以前的错误中恢复;正在停止编译
它是一个链表
发布于 2010-12-12 00:29:02
你不应该在C++中使用NULL,而应该使用0。并且您不需要强制转换空指针:任何指针类型都可以指向空指针。而且,如果可以避免这些问题,就不应该在C++中使用void指针。实际上,如果可以避免使用原始指针,就不应该使用原始指针。如果可以使用malloc(),就不应该在C++中使用new。也就是说,如果赋值的左侧不是void指针,则必须强制转换malloc()的返回值:
node = (NODE*)malloc(sizeof(NODE))https://stackoverflow.com/questions/4417617
复制相似问题