I am making a singly linked list :
#include <conio.h>
#include <iostream>
#include <stdlib.h>
using namespace std;
struct node
{
int a;
struct node *ptr;
};
node::node(int p) : {}
struct node *head;
void create(int d)
{
if(head==NULL)
{
head->a=d;
head->ptr=NULL;
}
else
{
struct node* temp =(struct node*) malloc(sizeof(struct node));
temp=head;
while(temp==NULL)
temp=temp->ptr;
temp->a=d;
temp->ptr=NULL;
}
}
void display()
{
struct node* temp =(struct node) malloc(sizeof(struct node));
temp=head;
while(temp==NULL)
{
cout<<temp->a<<" --> ";
temp=temp->ptr;
}
cout<<endl;
}
int main()
{
head=NULL;
create(5);
create(6);
create(8);
display();
return 0;
}
I am getting this error when I try to compile it:
..\linkedlist.cpp: In function 'void display()':
..\CPP\linkedlist.cpp:36:61: error: no matching function for call to 'node::node(void*)'
..\CPP\linkedlist.cpp:8:1: note: candidates are: node::node()
..\CPP\linkedlist.cpp:8:1: note: node::node(const node&)
Now, I am a rookie in coding and when I googled this problem, I found that a default constructor have to be constructed. I know how to create a constructor but not a member initialized list constructor.
hlp me, pls b0ss.
Aucun commentaire:
Enregistrer un commentaire