Hello everyone.

I've been trying to implement a linked list in C++. I found this implementation on the web, where they created a struct for the list's nodes. When trying to add a new node to the list, I get this error:

List.C: In member function `bool Linked::addNode(Point)':
List.C:23: error: no matching function for call to `Linked::node::node()'
List.H:35: note: candidates are: Linked::node::node(const Linked::node&)

And here's my Code, and thank you very much.. :)

List.H

#ifndef _AUXILIARY_H_
#define _AUXILIARY_H_
#include <string.h>
#include <math.h>

class Linked
{
 
 
 public:
	// Constructor: initializes a set of nodes
	Linked();
  
	// Linked methods
	bool addNode(Point p);
	bool removeNode(int index);
	bool getNode(int index, Point* p) const;
	bool setNode(int index, Point p);
	int getNodesCount() const;
	
	// Destructor: delete the set of nodes
	~Linked();

 private:
	// Definition of the nodes on the array of nodes
	/*typedef struct _Node* pNode;
	typedef struct _Node
	{
		Point pt;
		int index;
		Node *next;
	} 	Node;
	*/
	struct node
	{
		Point pt;
		int index;
		node *next;
	} *pLinked;
};

#endif // _AUXILIARY_H_

List.C

#include <string.h>
#include "List.H"

Linked::Linked()
{
     pLinked=NULL;
}

bool Linked::addNode(Point p)
{
	node *q,*t;
	int i=0;
	q = pLinked;
	
	while (q+i)
	{
		if ((q->pt.getX() == p.getX()) && (q->pt.getY() == p.getY()))
			return FALSE;
		q = q->next;
		i++;
	}
			
	t = new node;
	t->pt.setPoint(p);
	t->index = getNodesCount();
	t->next = q->next;
	q->next = t;
	
	return TRUE;
}

bool Linked::removeNode(int index)
{
    node *q,*r;
	q = pLinked + index;
	r = q - 1;
	if (q == NULL) 
		return FALSE;
	r->next = q->next;
	delete q;
	return TRUE;
}

bool Linked::setNode(int index, Point p)
{
	node *q;
	q = pLinked + index;
	if (q == NULL) 
		return FALSE;
	p.setPoint(q->pt);
	return TRUE;
}

int Linked::getNodesCount() const
{
	node *q;
	int count=0;
	for( q=pLinked ; q != NULL ; q = q->next )
        count++;
	return count;
}

Linked::~Linked()
{
	node *q;
	if( pLinked == NULL )
		return;
	while( pLinked != NULL )
	{
		q = pLinked->next;
		delete pLinked;
		pLinked = q;
	}
}

The compiler is not generating a default constructor for your struct. I'm not absolutely sure why, so I won't speculate and steer you in the wrong direction. Where does Point come from?

Point comes from a different class, which compiles just fine. Do you suspect I need to create a constructor for the struct?

Thank you everyone for your responses.
The problem has been solved. It turns out, when defining my Point class, I did not create a default constructor. :)

Glad you figured it out. I tried reinventing the Point class, but I wasn't reproducing the problem.

This question has already been answered. Start a new discussion instead.