我正在用 C++ 编写这个链表程序
当我测试程序时,我得到了错误
linkedlist.cpp:5:24:错误:隐式声明的“constexpr LinkedList::LinkedList()”的定义 LinkedList::LinkedList(){
这是代码
链接列表.h 文件:
#include "node.h"
using namespace std;
class LinkedList {
Node * head = nullptr;
int length = 0;
public:
void add( int );
bool remove( int );
int find( int );
int count( int );
int at( int );
int len();
};
链接列表.cpp 文件:
#include "linkedlist.h"
#include <iostream>
using namespace std;
LinkedList::LinkedList(){
length = 0;
head = NULL;
}
/*and all the methods below*/
请帮忙。
原文由 Leslie Zhou 发布,翻译遵循 CC BY-SA 4.0 许可协议
您应该在类内声明构造函数,以便在类外定义 cunstructor。否则你应该在类本身中定义它。你的类应该是这样的。