全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1156
推到 Plurk!
推到 Facebook!

我寫了一個程式會有Linker Error請各位前輩幫我看一下

尚未結案
jackwu
一般會員


發表:28
回覆:54
積分:16
註冊:2002-08-18

發送簡訊給我
#1 引用回覆 回覆 發表時間:2002-09-16 18:05:46 IP:211.75.xxx.xxx 未訂閱
我現在使用template來寫一個Queue 可是才開始寫push時,來做測試時,就會出現Linker error 請各位前輩幫我看看..謝謝  
 
Unit1.cpp
//---------------------------------------------------------------------------
#include 
#pragma hdrstop    #include "Unit1.h"
#include "MyQueue.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
Queue〈int〉 Q;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::PushClick(TObject *Sender)  
{
  int x;
  x = StrToInt(Edit->Text);
  Q.Push(x);
}
//---------------------------------------------------------------------------    MyQueue.cpp
//---------------------------------------------------------------------------
#include "Unit1.h"
#include "MyQueue.h"    template
Queue::Queue(int MaxQueueSize):MaxSize(MaxQueueSize)
{
  array = new int[MaxQueueSize];
  top = -1;
}
//---------------------------------------------------------------------------
template
Queue::~Queue()
{
  delete [] array;
}
//---------------------------------------------------------------------------
template
void Queue::Push(const QueueType& x)
{
    array[++top] = x;
}    MyQueue.h
//---------------------------------------------------------------------------
#ifndef MYQUEUEH
#define MYQUEUEH
#define Queue_Max_Num 4    template〈class QueueType〉
class Queue
{
  private:
        int *array;
        int top;
        int x;
  public:
        Queue(int MaxQueueSize = Queue_Max_Num);
        ~Queue();
        void Push(const QueueType& item);
};
#endif
會出現下面的Error [Linker Error] Unresolved external 'Queue::Queue(int)' referenced from D:\測試程式\複製 -QUEUE\UNIT1.OBJ [Linker Error] Unresolved external 'Queue::~Queue()' referenced from D:\測試程式\複製 -QUEUE\UNIT1.OBJ [Linker Error] Unresolved external 'Queue::Push(const int&)' referenced from D:\測試程式\複製 -QUEUE\UNIT1.OBJ
jackwu
一般會員


發表:28
回覆:54
積分:16
註冊:2002-08-18

發送簡訊給我
#2 引用回覆 回覆 發表時間:2002-09-23 12:38:44 IP:211.75.xxx.xxx 未訂閱
自己回覆 我已經接決了,將#include "Queue.h"改成#include "Queue.cpp" 就不會出現Linker Error
系統時間:2024-04-25 1:35:40
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!