我的程序中出现LNK 2019错误 [英] LNK 2019 error in my program

查看:65
本文介绍了我的程序中出现LNK 2019错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,抱歉这么糟糕的问题。我不清楚在那里写什么。我正在编写一个小型桌面银行应用程序作为一个学期结束的编程项目(顺便说一下,我是电气工程师,而不是软件)。所以我遇到了LNK 2019错误,如下图所示。我已经尝试了两个小时来解决它但尚未成功。你可以看到这个程序非常简单。 List.cpp文件基本上是链表的实现,它在主函数的控制台上显示。



如果你帮我解决这个问题,我将非常感激。< br $> b $ b

https://i.imgur.com/oA3euuk.png



Node.h文件

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文件




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文件





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文件





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.

推荐答案

链接器错误2019 ,我猜你没有包含在项目中的lisp.cpp。使用添加到项目...



但是查看代码我看到了一些错误。就像这里:

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:
void List::printList() {
     Node *temp = head;

当使用时只使用你不需要创建对象的指针。 insertAtPosition与当前和之前相同。



您的实现需要一些内存管理。规则每个新的需要删除。 List的析构函数是删除列表中所有成员的好地方。



提示:编写Node的构造函数(名称,密码,年龄)

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)


这篇关于我的程序中出现LNK 2019错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆