我在visual studio中收到错误LNK2019 [英] I got error LNK2019 in visual studio

查看:71
本文介绍了我在visual studio中收到错误LNK2019的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用visual studio时出错。下面是错误。







错误1错误LNK2019:未解析的外部符号public:void __thiscall Heap :: addItem(int,int)(?addItem @ Heap @@ QAEXHH @ Z)在函数_main中引用



我尝试了什么:



i我试图构建我的项目但不幸的是由于这个错误我无法构建它。

i got an error using visual studio..error is below.



Error 1 error LNK2019: unresolved external symbol "public: void __thiscall Heap::addItem(int,int)" (?addItem@Heap@@QAEXHH@Z) referenced in function _main

What I have tried:

i am tried to build my project but unfortunately due to this error i can't built it.

推荐答案

好吧,你没有给我们任何代码,或者说明你是在使用第三方(或自己创建的dll),所以我能做的最好的事情是指向链接器工具错误LNK2019 [ ^ ]这里有很多会导致此错误的事情



如果您有代码或更多信息可以帮助我们,请使用'改进任务你问题底部的离子链接。请勿将信息发布回此
Well, you dont give us any code, or indicate if you're using a 3rd party (or self created dll), so the best thing I can do is point you to Linker Tools Error LNK2019[^] where there's a long list of things that will cause this error

If you do have code or more information that may help us to help you, please use the 'Improve question' link at the bottom of your question. DO NOT post the information back to this


//----------------------------------------------------------------
// HeapItem.h
// Simple class with which to build the heap demonstration.
//
// Author: Dr. Rick Coleman
//----------------------------------------------------------------
#ifndef HEAPITEM_H
#define HEAPITEM_H

class HeapItem
{
private:
	int m_iKey;                              // Heap item priority key
	double m_dData;                         // Dummy data value

public:
	HeapItem();  // Default constructor
	HeapItem(int key, double data);     // Constructor
	~HeapItem();                         // Destructor
	int getKey();                         // Return item priority
	void setKey(int key);               // Set the priority key value
	double getData();                    // Return data item
	void setData(double data);
	// Set the data item value
};

#endif




//----------------------------------------------------------------
// HeapItem.cpp
// Implementation file for a simple class with which to build 
//          the heap demonstration.
//
// Author: Dr. Rick Coleman
//----------------------------------------------------------------
#include "HeapItem.h"

//-----------------------------------
// Default constructor
//-----------------------------------
HeapItem::HeapItem()
{
	m_iKey = 0;
	m_dData = 0.0;
}

//-----------------------------------
// Constructor
//-----------------------------------
HeapItem::HeapItem(int key, double data)
{
	m_iKey = key;
	m_dData = data;
}

//-----------------------------------
// Destructor
//-----------------------------------
HeapItem::~HeapItem()
{
}

//-----------------------------------
// Return item priority
//-----------------------------------
int HeapItem::getKey()
{
	return m_iKey;
}

//-----------------------------------
// Set the priority key value
//-----------------------------------
void HeapItem::setKey(int key)
{
	m_iKey = key;
}

//-----------------------------------
// Return data item
//-----------------------------------
double HeapItem::getData()
{
	return m_dData;
}

//-----------------------------------
// Set the data item value
//-----------------------------------
void HeapItem::setData(double data)
{
	m_dData = data;
}




// Heap.h
// Demonstration of a heap implemented as an array.  Adapted from
//   sample code in C++ Plus Data Structures, 4th ed. by
//   Nell Dale.
// Author: Dr. Rick Coleman
//----------------------------------------------------------------
#ifndef HEAP_H
#define HEAP_H

#include "HeapItem.h"

class Heap
{
private:
	HeapItem     *m_Elements;                 // Pointer to dynamically allocated array
	int          m_iNumElements;              // Number of elements in the heap
	int          m_iHeapLength;               // Size of the array

public:
	Heap(int size = 10);                     // Parameterized constructor
	~Heap();                                 // Destructor
	void ReheapDown(int root, int bottom);   // Reheap after removing item
	void ReheapUp(int root, int bottom);     // Reheap after inserting item
	bool Enqueue(HeapItem *item);            // Add an item to the heap
	bool Enqueue(int key, double data);      // Add an item to the heap
	HeapItem *Dequeue();                     // Get item at the root
	int getNumElements();                    // Return number of elements in the heap
	void printAll();                         // Print all the elements in the heap
	int addItem(int);
};

#endif
////




// Heap.cpp
// Demonstration of a heap implemented as an array.  Adapted from
//   sample code in C++ Plus Data Structures, 4th ed. by
//   Nell Dale.
// Author: Dr. Rick Coleman
//----------------------------------------------------------------
#pragma warning(disable:4996) // Tell Microsoft to not give warnings when 
// I use K&R char arrays as strings.  I know
// what I'm doing and don't need MS to protect me.
#include <iostream>
#include "Heap.h"

using namespace std;

//---------------------------------------
// Parameterized default constructor
//---------------------------------------
Heap::Heap(int size)
{
	// Create heap of given size
	m_Elements = new HeapItem[size];
	m_iNumElements = 0;
	m_iHeapLength = size;
}

//---------------------------------------
// Destructor
//---------------------------------------
Heap::~Heap()
{
	delete[] m_Elements;
}

//---------------------------------------
// Reheap after removing item
//---------------------------------------
void Heap::ReheapDown(int root, int bottom)
{
	int maxChild;
	int rightChild;
	int leftChild;
	HeapItem temp;
	

	leftChild = root * 2 + 1;          // Get index of root's left child
	rightChild = root * 2 + 2;          // Get index of root's right child

	// Check base case in recursive calls.  If leftChild's index is less
	// than or equal to the bottom index we have not finished recursively 
	// reheaping.
	if (leftChild <= bottom)
	{
		if (leftChild == bottom)          // If this root has no right child then 
		{
			maxChild = leftChild;     //     leftChild must hold max key
		}
		else
		{     // Get the one lowest in the tree (highest index in the array)
			if (m_Elements[leftChild].getKey() <= m_Elements[rightChild].getKey())
				maxChild = rightChild;
			else
				maxChild = leftChild;
		}
		if (m_Elements[root].getKey() < m_Elements[maxChild].getKey())
		{
			// Swap these two elements
			temp = m_Elements[root];
			m_Elements[root] = m_Elements[maxChild];
			m_Elements[maxChild] = temp;
			// Make recursive call till reheaping completed
			ReheapDown(maxChild, bottom);
		}
	}
}

//---------------------------------------
// Reheap after inserting item
//---------------------------------------
void Heap::ReheapUp(int root, int bottom)
{
	int parent;
	HeapItem temp;

	// Check base case in recursive calls.  If bottom's index is greater
	// than the root index we have not finished recursively reheaping.
	if (bottom > root)
	{
		parent = (bottom - 1) / 2;
		if (m_Elements[parent].getKey() < m_Elements[bottom].getKey())
		{
			// Swap these two elements
			temp = m_Elements[parent];
			m_Elements[parent] = m_Elements[bottom];
			m_Elements[bottom] = temp;
			// Make recursive call till reheaping completed
			ReheapUp(root, parent);
		}
	}
}

//---------------------------------------
// Add an item to the heap
//---------------------------------------
bool Heap::Enqueue(HeapItem *item)
{
	if (m_iNumElements < m_iHeapLength)
	{
		m_Elements[m_iNumElements] = *item; // Copy item into array
		ReheapUp(0, m_iNumElements);
		m_iNumElements++;
		return true;
	}
	return false;
}

//---------------------------------------
// Add an item to the heap
//---------------------------------------
bool Heap::Enqueue(int key, double data)
{
	bool retVal;
	HeapItem *temp = new HeapItem(key, data);
	retVal = Enqueue(temp);
	delete temp;  // Delete this dynamically created one
	return retVal;
}

//---------------------------------------
// Get item at the root
//---------------------------------------
HeapItem *Heap::Dequeue()
{
	HeapItem *temp = new HeapItem(m_Elements[0].getKey(), m_Elements[0].getData());
	m_iNumElements--;
	// Copy last item into root
	m_Elements[0] = m_Elements[m_iNumElements];
	// Reheap the tree
	ReheapDown(0, m_iNumElements - 1);
	if (m_iNumElements == 0)
		return NULL;
	else
		return temp;
}

//---------------------------------------
// Return number of elements in the heap
//---------------------------------------
int Heap::getNumElements()
{
	return m_iNumElements;
}

//---------------------------------------
// Print all the elements in the heap
//---------------------------------------
void Heap::printAll()
{
	for (int i = 0; i<m_iNumElements; i++)
	{
		cout << "Heap element " << i << ". key=" << m_Elements[i].getKey() << "  data=" <<
			m_Elements[i].getData() << endl;
	}
}
// Code211_Heap.cpp
// Demonstration of a heap implemented as an array.  Adapted from
//   sample code in C++ Plus Data Structures, 4th ed. by
//   Nell Dale.
// Note: Even though we think of a heap as a tree-like structure
//       it is very difficult to implement a heap as a linked
//       data type.  Since a heap must always be a Complete
//       binary tree it is actually rather easy to implement
//       such a structure in an array.
// Author: Dr. Rick Coleman
//===============================================================
#pragma warning(disable:4996) // Tell Microsoft to not give warnings when 
                                     // I use K&R char arrays as strings.  I know
                                     // what I'm doing and don't need MS to protect me.

#include "Heap.h"
#include "HeapItem.h"
#include <iostream>

using namespace std;

void main()

{
	Heap *theHeap = new Heap(10);  // Create a heap of the default size

	cout << "Building the heap and adding items\n\n";

	// Add some items
	
     theHeap->addItem(1);
     theHeap->addItem(4);
     theHeap->addItem(4);
     theHeap->addItem(4);
     theHeap->addItem(2);
     theHeap->addItem(1);
     theHeap->addItem(6);

     // This will build a heap that looks like this
     //                    789 
     //                   /   \
     //                456     678
     //                / \     / \
     //              123 345 234 567

     // See what we got
     cout << "Elements in the heap.\n";
     theHeap->printAll();
	 HeapItem *temp;
     cout << "Dequeuing items from the heap.\n\n";
     while((temp = theHeap->Dequeue()) != NULL)
     {
		cout << "Dequeueing " << temp->getKey() << endl;
		delete temp; // delete this one
		// See what we have left
		cout << "Elements in the heap.\n";
		theHeap->printAll();
		cout << endl;
     }
}


Heap.h
int addItem(int);

- 好



示例程序使用堆

- good

Example Program Using Heap

theHeap->addItem(1);

- 好



链接错误?从您的程序

- good

Link Error ? From your program

Quote:

Heap :: addItem(int,int)

Heap::addItem(int,int)





Heap类中没有



there is no definition in the Heap class for

addItem(int, int);

所以我不知道你试图做什么

so I dont know what you have tried to do


这篇关于我在visual studio中收到错误LNK2019的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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