0

I am trying to make a library system using C++, where i would ask the user for input for book name, author, and year and it will be stored in a linked list. I have done the following so far in the header file (which seems to have no errors)

#include <iostream>
#include <string>
#include "LinkedList.h"
using namespace std;

class LinkedList {

private:

struct BookNode {
    string Book_Title;
    string Author_Name;
    int Year_of_Publishing ;
    BookNode* next;
};
public:

LinkedList();
void addInfo(string,string, int);
void print();
};

and for the .cpp

void LinkedList::addInfo(string data1,string data2, int data3)
{
BookNode* n = new BookNode;
n->Book_Title = data1;
n->Author_Name = data2;
n->Year_of_Publishing = data3;
n->next = NULL;
curr = head;

However, for this its giving the error

LinkedList::addInfo(<error-type>, <error-type>, int)" (declared at line 27 of

What am i doing wrong?

juanchopanza
  • 223,364
  • 34
  • 402
  • 480
Muneeb Rehman
  • 135
  • 2
  • 10

1 Answers1

2

In order to use string as parameter type in the header you need to do two things:

  • The header must have #include <string>
  • Replace string with std::string, or add using namespace std (not recommended)


#include <string>

class LinkedList {
...
    void addInfo(std::string, std::string, int);
};
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523