[[अद्यतन]] समारोह में संदर्भित -> अगर मैं अपने program.cpp में "Queue.cpp" # शामिल है, यह सिर्फ ठीक काम करता है। यह जरूरी नहीं होना चाहिए, है ना?सी ++ - LNK2019 त्रुटि अनसुलझे बाह्य प्रतीक [टेम्पलेट वर्ग के निर्माता और नाशक] _main
अरे सब - मैं दृश्य स्टूडियो 2010 का उपयोग कर रहा है और मुसीबत एक त्वरित और गंदा कतार कार्यान्वयन को जोड़ने है। मैं एक खाली Win32 कंसोल आवेदन के साथ शुरू किया, और सभी फ़ाइलों को परियोजना में मौजूद हैं। Verbosity के लिए, मेरी त्रुटि डुप्लिकेट करने के लिए यहां पूरा कोड है। मुझे एहसास है कि कुछ कोड वास्तव में गलत हो सकते हैं। मुझे अभी तक इसका परीक्षण करने का मौका नहीं मिला है क्योंकि मैं अभी तक इसे लिंक करने में सक्षम नहीं हूं।
Queue.hpp
#ifndef ERROR_CODE
#define ERROR_CODE
enum Error_Code
{
Success,
Underflow,
Overflow
};
#endif // ERROR_CODE
#ifndef QUEUE
#define QUEUE
template<class T>
struct Queue_Node
{
T data;
Queue_Node *next;
Queue_Node()
{
next = NULL;
}
Queue_Node(T pData)
{
data = pData;
next = NULL;
}
Queue_Node(T pData, Queue_Node *pNext)
{
data = pData;
next = pNext;
}
};
template<class T>
class Queue
{
public:
Queue();
Error_Code Serve();
Error_Code Append(T item);
T Front();
~Queue();
private:
void Rescursive_Destroy(Queue_Node<T> *entry);
Queue_Node<T> *front, *rear;
};
#endif // QUEUE
Queue.cpp
#include "Queue.hpp"
template <class T>
Queue<T>::Queue()
{
this->front = this->rear = NULL;
}
template<class T>
Error_Code Queue<T>::Serve()
{
if(front == NULL)
return Underflow;
Queue_Node *temp = this->front;
this->front = this->front->next;
delete temp;
}
template<class T>
Error_Code Queue<T>::Append(T item)
{
Queue_Node *temp = new Queue_Node(item);
if(!temp)
return Overflow;
if(this->rear != NULL)
this->rear->next = temp;
this->rear = temp;
return Success;
}
template<class T>
T Queue<T>::Front()
{
if(this->front == NULL)
return Underflow;
return this->front->data;
}
template<class T>
Queue<T>::~Queue()
{
this->Rescursive_Destroy(this->front);
}
template<class T>
void Queue<T>::Rescursive_Destroy(Queue_Node<T> *entry)
{
if(entry != NULL)
{
this->Recursive_Destroy(entry->next);
delete entry;
}
}
program.cpp
#include "Queue.hpp"
int main()
{
Queue<int> steve;
return 0;
}
और त्रुटियों ...
Error 1 error LNK2019: unresolved external symbol "public: __thiscall Queue<int>::~Queue<int>(void)" ([email protected]@@[email protected]) referenced in function _main C:\[omitted]\Project2_2\Project2_2\program.obj Project2_2
Error 2 error LNK2019: unresolved external symbol "public: __thiscall Queue<int>::Queue<int>(void)" ([email protected]@@[email protected]) referenced in function _main C:\[omitted]\Project2_2\Project2_2\program.obj Project2_2
निम्नलिखित ज फ़ाइल
.cpp फ़ाइल में करते हैं; आपको हेडर में प्रत्येक वर्ग के लिए गार्ड शामिल करने की आवश्यकता नहीं है, और ऐसा करने से संघर्ष की संभावना अधिक होती है। इसके बजाय, उस हेडर के फ़ाइल नाम के आधार पर, पूरे हेडर के चारों ओर गार्ड को शामिल करें। यह मानक अभ्यास और अन्य फ़ाइल नामों में चलाने की बहुत कम संभावना है। –
[लिंकर त्रुटि LNK2019] का डुप्लिकेट (http://stackoverflow.com/questions/3680312/linker-error-lnk2019) (यह प्रश्न हर सप्ताह पांच बार पूछता है) –