Click here to Skip to main content
15,889,843 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
C++
#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

C++
#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

C++
#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

C++
#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.
Posted
Updated 13-May-18 20:35pm
Comments
Richard MacCutchan 13-May-18 3:44am    
What is the full text of the error message?
CPallini 13-May-18 16:48pm    
Did you include the List.cpp file in your project?

1 solution

The linker error 2019 and I guess that you havent the lisp.cpp included in the project. Use "Add to project..."

But looking at your code I see some bugs. Like here:
C++
void List::printList() {
     Node *temp = head;
When use only use the pointer you dont need to create a object. The same at insertAtPosition with current and previous.

Your implementation needs some memory managment. Rule every new needs a delete. The destructor of List is a good place to delete all members of the list.

Tip: Write a constructor for Node(name,password,age)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900