First of all, sorry for such a bad title of question. I wasn't clear what to write there. I am writing a small desktop banking application as a end semester programming project (by the way I am Electrical Engineer not Software just to mention). So I am encountering LNK 2019 error as you can see in the following picture. I had been trying for two hours to resolve it but haven't succeeded yet. You can see this program its quite simple. List.cpp file is basically implementation of linked list and it is displayed on console in main function.
I will be really grateful if you help me with this issue.
https://i.imgur.com/oA3euuk.png
Node.h file
#pragma once
#ifndef NODE_H
#define NODE_H
#include <string>
using namespace std;
class Node {
friend class List;
public:
string name;
string password;
int age;
Node *next;
};
#endif
List.h file
#pragma once
#ifndef LIST_H
#define LIST_H
#include <string>
#include "Node.h"
using namespace std;
class List {
public:
Node *head, *tail;
public:
List();
void createNode(string name, string password, int age);
void printList();
void insertAtStart(string name, string password, int age);
void insertAtPosition(int pos, string name, string password, int age);
};
#endif
List.cpp file
#include <iostream>
#include "Node.h"
#include "List.h"
using namespace std;
List::List() {
head = NULL;
tail = NULL;
}
void List::createNode(string name ,string password, int age) {
Node *node = new Node;
node->age = age;
node->name = name;
node->next = NULL;
if (head == NULL) {
head = node;
tail = node;
node = NULL;
}
else {
tail->next = node;
tail = node;
}
}
void List::printList() {
Node *temp = new Node;
temp = head;
while (temp != NULL) {
cout << "Age of Person is : " <<temp->age << "\t";
cout << "Name of a Person is : " << temp->name << "\n";
temp = temp->next;
}
}
void List::insertAtStart(string name, string password, int age) {
Node *node = new Node;
node->age = age;
node->name = name;
node->next = head;
head = node;
}
void List::insertAtPosition(int pos,string name, string password, int age) {
Node *node = new Node;
Node *current = new Node;
Node *previous = new Node;
current = head;
for (int i = 1; i < pos; i++) {
previous = current;
current = current->next;
}
node->age = age;
node->name = name;
previous->next = node;
node->next = current;
}
main.cpp file
#include <iostream>
#include "List.h"
int main() {
List list;
list.createNode("Roshan", "ros", 10);
list.insertAtStart("Bablo", "bab", 60);
list.createNode("Gudda", "guda", 20);
list.createNode("Guddu", "gudu", 89);
list.insertAtPosition(3, "Billa", "bil", 111);
list.printList();
getchar();
return 0;
}
What I have tried:
Well I have been trying to fix this problem by reading different material on the internet but yet none of them helped me.