I'm writing this linked list program with C++
When I test the program, I got the error
linkedlist.cpp:5:24: error: definition of implicitly-declared 'constexpr LinkedList::LinkedList()' LinkedList::LinkedList(){
Here's the code
linkedlist.h file:
#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();
};
linkedlist.cpp file:
#include "linkedlist.h"
#include <iostream>
using namespace std;
LinkedList::LinkedList(){
length = 0;
head = NULL;
}
/*and all the methods below*/
please help.
Declare the parameterless constructor in the header file:
class LinkedList {
{
....
public:
LinkedList();
....
}
You are defining it in the .cpp file without actually declaring it. But since the compiler provides such a constructor by default (if no other constructor is declared), the error clearly states that you are trying to define an implicitly-declared constructor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With