Hi
I have tried to implement Linked-List data structure and i was folowing a guide but i have an error
in line 12 in contactlist.h
I have included contact.h
properly but still not working :-/
contact.h
#ifndef CONTACT_H
#define CONTACT_H
#include <iostream>
#include <string>
#include "contactlist.h"
class Contact
{
private:
std::string name;
Contact *next;
public:
friend class ContactList;
Contact(std::string);
std::ostream& operator<<(std::ostream& output);
};
#endif // CONTACT_H
contactlist.h
#ifndef CONTACTLIST_H
#define CONTACTLIST_H
#include <iostream>
#include <string>
#include "contact.h"
class ContactList
{
private:
int size;
Contact *head; // The error is here
public:
ContactList();
void AddtoHead(const std::string &n);
};
#endif // CONTACTLIST_H
contact.cpp
#include "contact.h"
Contact::Contact(std::string _Name = "Default Name"): name(_Name), next(NULL)
{}
std::ostream& Contact::operator<<(std::ostream& output){
return output<<this->name<<std::endl<<"Next Node: "<<this->next<<std::endl;
}
contactlist.cpp
#include "contactlist.h"
#include "contact.h"
ContactList::ContactList(): head(NULL), size(0)
{}
void ContactList::AddtoHead(const std::string &n)
{
Contact *NewNode = new Contact(n);
if(head == NULL)
head = NewNode;
else
{
NewNode->next = head;
head = NewNode;
}
}
Error
C:\Users\*****\Documents\Qt Creator\Projects\Linked-List\contactlist.h:12: error: 'Contact' does not name a type
Contact *head;
^