全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:2165
推到 Plurk!
推到 Facebook!
[<<] [1] [2] [>>]

linker error

尚未結案
joen0000
一般會員


發表:47
回覆:47
積分:18
註冊:2004-11-07

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-11-07 14:00:57 IP:61.230.xxx.xxx 未訂閱
各位大大我看ㄌㄧ些文章ㄌ 可是還是弄不出來 請大大幫幫小弟ㄉ問題...Orz
pwipwi
版主


發表:68
回覆:629
積分:349
註冊:2004-04-08

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-11-07 15:00:14 IP:211.76.xxx.xxx 未訂閱
joen0000你好:     應該是friend function沒有弄好,試著加入:  
// 前置宣告
class items;
std::ostream& operator<<(ostream&,const items&);
// 前置宣告    class items{
...
...
    public:
        // friend宣告在此
        friend std::ostream& operator<<(ostream&,const items&);
}    // 實作
std::ostream& operator<<(ostream&,const items&)
{
    ...
    ...
}
 
joen0000
一般會員


發表:47
回覆:47
積分:18
註冊:2004-11-07

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-11-07 19:54:33 IP:61.230.xxx.xxx 未訂閱
//不知怎ㄇ宣告耶..懇請pwipwi再次幫忙...Orz template<> class Stack { public: friend std::ostream &operator << ( std::ostream& , const keytype & ) ; Stack(int maxstacksize=DefaultSize); Boolean isfull(); Boolean isempty(); void add(const keytype &item); keytype* Delete(keytype &); int top; keytype *stack; int maxsize; }; template<> Stack::Stack(int maxstacksize):maxsize(maxstacksize) { stack=new keytype[maxstacksize]; top=-1; } template<> Boolean Stack::isfull() { if(top==maxsize-1) return true; else return false; } template<> Boolean Stack<>::isempty() { if(top==-1) return true; else return false; } template<> void Stack<>::add(const keytype & x) { if(!isfull()) stack[ top]=x; } template<> keytype* Stack<>::Delete(keytype &x) { if(!isempty()) x=stack[top--]; else return 0; return &x; } template<> std::ostream& operator<<(std::ostream &os,const Stack &s) { os<<"top="<裡是keytype ㄎ..好怪< >ㄉ會不見..... 發表人 - joen0000 於 2004/11/07 20:13:13 發表人 - joen0000 於 2004/11/07 20:14:00
pwipwi
版主


發表:68
回覆:629
積分:349
註冊:2004-04-08

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-11-07 21:52:27 IP:211.76.xxx.xxx 未訂閱
參考下面的文章,是否能解決問題? http://delphi.ktop.com.tw/topic.php?TOPIC_ID=48746
joen0000
一般會員


發表:47
回覆:47
積分:18
註冊:2004-11-07

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-11-07 23:43:33 IP:61.230.xxx.xxx 未訂閱
#ifndef Unit1H #define Unit1H #ifndef StackH #define StackH 如果不打 #ifndef StackH #define StackH 就會出現一樣ㄉ 如果不打 #ifndef Unit1H #define Unit1H 也是出現 發表人 - joen0000 於 2004/11/08 00:59:01
pwipwi
版主


發表:68
回覆:629
積分:349
註冊:2004-04-08

發送簡訊給我
#6 引用回覆 回覆 發表時間:2004-11-08 00:56:25 IP:211.76.xxx.xxx 未訂閱
沒有加上#endif?
joen0000
一般會員


發表:47
回覆:47
積分:18
註冊:2004-11-07

發送簡訊給我
#7 引用回覆 回覆 發表時間:2004-11-08 01:00:56 IP:61.230.xxx.xxx 未訂閱
引言: 沒有加上#endif?
恩恩有阿大大
pwipwi
版主


發表:68
回覆:629
積分:349
註冊:2004-04-08

發送簡訊給我
#8 引用回覆 回覆 發表時間:2004-11-08 01:37:55 IP:211.76.xxx.xxx 未訂閱
你要不要寄程式給我? 或者波上完整的程式, (記得加上程式區段標記) pwipwi@ms66.hinet.net
joen0000
一般會員


發表:47
回覆:47
積分:18
註冊:2004-11-07

發送簡訊給我
#9 引用回覆 回覆 發表時間:2004-11-08 02:31:07 IP:61.230.xxx.xxx 未訂閱
[/quote] 糟糕我不會用outlook寄信 要設定什ㄇㄉ 有寄可是無法送出去 我只好把程式po上來ㄌ 不好意思阿大大    我是在做stack堆疊ㄉclass
 
#ifndef Unit1H
#define Unit1H
#ifndef StackH
#define StackH
//宣告
template
 class Stack;
template
 std::ostream &operator << ( std::ostream& , const Stack & ) ;
//宣告結束
//開始class
template
class Stack
{     public:
//freind operator   
  friend std::ostream &operator << <>( std::ostream& , const keytype & ) ;
   Stack(int maxstacksize=DefaultSize);
   Boolean isfull();
   Boolean isempty();
   void add(const keytype &item);
   keytype* Delete(keytype &);       int top;
   keytype *stack;
   int maxsize;       };
 //class 結束       template
 Stack::Stack(int maxstacksize):maxsize(maxstacksize)
     {
       stack=new keytype[maxstacksize];
       top=-1;
     }
template
     Boolean  Stack::isfull()
     {
         if(top==maxsize-1) return true;
           else return false;
     }
template
     Boolean  Stack::isempty()
     {
        if(top==-1) return true;
           else return false;
     }
template
     void Stack::add(const keytype & x)
       {
        if(!isfull())
           stack[  top]=x;
       }
template
     keytype* Stack::Delete(keytype &x)
      {
         if(!isempty())
          x=stack[top--];
          else return 0;
         return &x;
      }          template
//frind operator ㄉ內容   
 std::ostream& operator<<(std::ostream &os,const Stack &s)
 {
  os<<"top="<
發表人 - joen0000 於 2004/11/08 22:21:44
blk5743
高階會員


發表:34
回覆:371
積分:236
註冊:2003-11-17

發送簡訊給我
#10 引用回覆 回覆 發表時間:2004-11-08 09:32:59 IP:61.66.xxx.xxx 未訂閱
#ifndef Unit1H #define Unit1H 後面也要加 #endif變成 #ifndef Unit1H #define Unit1H #endif
joen0000
一般會員


發表:47
回覆:47
積分:18
註冊:2004-11-07

發送簡訊給我
#11 引用回覆 回覆 發表時間:2004-11-08 10:41:17 IP:61.230.xxx.xxx 未訂閱
引言: #ifndef Unit1H #define Unit1H 後面也要加 #endif變成 #ifndef Unit1H #define Unit1H #endif
很感謝大大ㄉ幫忙...加ㄌ這ㄍ之後又回到 linker error ........ㄌ
pwipwi
版主


發表:68
回覆:629
積分:349
註冊:2004-04-08

發送簡訊給我
#12 引用回覆 回覆 發表時間:2004-11-08 18:54:00 IP:211.76.xxx.xxx 未訂閱
joen0000你好:     Stack包含的element type也要實作friend iostream的函式。 比如  
Stack test;
// Myclass也要實作operator <<和operator >>
 
另外你可以按此文章的回應,看看如何加上程式的區段標記 發表人 -
joen0000
一般會員


發表:47
回覆:47
積分:18
註冊:2004-11-07

發送簡訊給我
#13 引用回覆 回覆 發表時間:2004-11-08 22:43:39 IP:61.230.xxx.xxx 未訂閱
引言: pwipwi大大你好: Myclass 實做operator<<和operator>>是要寫什ㄇ東東 不太了大大ㄉ意思 Myclass是不是等於我寫ㄉkeytype ?? 還有我要實做什ㄇ東西ㄋ??和怎ㄇ實做ㄋ?? 大大不好意思 本人功力不夠 還請大大幫忙 說ㄍ例子....>< face="Verdana, Arial, Helvetica"> 發表人 - joen0000 於 2004/11/08 22:46:04
joen0000
一般會員


發表:47
回覆:47
積分:18
註冊:2004-11-07

發送簡訊給我
#14 引用回覆 回覆 發表時間:2004-11-08 22:46:44 IP:61.230.xxx.xxx 未訂閱
    pwipwi大大你好: Myclass 實做operator<<和operator>>是要寫什ㄇ東東 不太了大大ㄉ意思 Myclass是不是等於我寫ㄉkeytype ?? 還有我要實做什ㄇ東西ㄋ??和怎ㄇ實做ㄋ?? 大大不好意思 本人功力不夠 還請大大幫忙 說ㄍ例子....
pwipwi
版主


發表:68
回覆:629
積分:349
註冊:2004-04-08

發送簡訊給我
#15 引用回覆 回覆 發表時間:2004-11-09 02:49:04 IP:211.76.xxx.xxx 未訂閱
完成以下的函式:  
 std::ostream& operator<<(std::ostream &os,const keytype &key)
 {
   ....
   ....
  return os;
 }     std::istream& operator>>(std::istream &is,keytype &key)
 {
   ....
   ....
  return is;
 }     
joen0000
一般會員


發表:47
回覆:47
積分:18
註冊:2004-11-07

發送簡訊給我
#16 引用回覆 回覆 發表時間:2004-11-09 02:58:50 IP:61.230.xxx.xxx 未訂閱
引言: pwipwi大大你好: Stack包含的element type也要實作friend iostream的函式這ㄍ要怎ㄇ實做阿ˋ 大大不好意思 本人功力不夠 還請大大幫忙 說ㄍ例子....>< face="Verdana, Arial, Helvetica">
joen0000
一般會員


發表:47
回覆:47
積分:18
註冊:2004-11-07

發送簡訊給我
#17 引用回覆 回覆 發表時間:2004-11-09 03:11:43 IP:61.230.xxx.xxx 未訂閱
 
template
 class Stack;
template
 std::ostream &operator << ( std::ostream& , const Stack & ) ;
template
class Stack
{     public:
  friend std::ostream &operator << <>( std::ostream& , const keytype & ) ;
  friend std::ostream& operator<<(std::ostream &,const keytype &);
  friend std::istream& operator>>(std::istream &is,keytype &);
   Stack(int maxstacksize=DefaultSize);
   Boolean isfull();
   Boolean isempty();
   void add(const keytype &);
   keytype* Delete(keytype &);       int top;
   keytype *stack_1;
   int maxsize;       };    template
 Stack::Stack(int maxstacksize):maxsize(maxstacksize)
     {
       stack_1=new keytype[maxstacksize];
       top=-1;
     }
template
     Boolean  Stack::isfull()
     {
         if(top==maxsize-1) return true;
           else return false;
     }
template
     Boolean  Stack::isempty()
     {
        if(top==-1) return true;
           else return false;
     }
template
     void Stack::add(const keytype & x)
       {
        if(!isfull())
           stack_1[++top]=x;
       }
template
     keytype* Stack::Delete(keytype &x)
      {
         if(!isempty())
          x=stack_1[top--];
          else return 0;
         return &x;
      }
      template
 std::ostream& operator<<(std::ostream &os,const Stack &s)
 {
  os<<"top="<
  std::ostream& operator<<(std::ostream &os,const keytype &key)
 {
   os<
 std::istream& operator>>(std::istream &is,keytype &key)
 {
   is>>key;
  return is;
 }
ㄎ....不知紅色ㄉ地方錯在哪裡 厚....我實在笨笨ㄉ...不好意思..希望大大還有耐心ㄉ繼續ㄉ指導我...Orz 發表人 - joen0000 於 2004/11/09 03:13:55
pwipwi
版主


發表:68
回覆:629
積分:349
註冊:2004-04-08

發送簡訊給我
#18 引用回覆 回覆 發表時間:2004-11-09 16:57:42 IP:211.76.xxx.xxx 未訂閱
joen0000你好:     撰寫template時,很重要的部分是type最後在cpp檔中是如何運用的。 以你的例子,你放上的程式碼都只有檔頭部份。這樣無法知道錯誤在那。 (因為不知道你的keytype用什麼?int? float? 還是自訂的型別?) 加上BCB在處理template friend function上非常複雜,大部分都是link 時出錯誤,很難單看標頭檔就可以debug。        建議你將整個專案打包,傳到站上的會員程式上傳區,這樣才能 讓大家幫你解決問題。
joen0000
一般會員


發表:47
回覆:47
積分:18
註冊:2004-11-07

發送簡訊給我
#19 引用回覆 回覆 發表時間:2004-11-10 00:57:06 IP:61.230.xxx.xxx 未訂閱
http://delphi.ktop.com.tw/topic.php?TOPIC_ID=59470 pwipwi大大 下面那ㄍ王子才可以下載喔... 有勞大大ㄌ...Orz 發表人 - joen0000 於 2004/11/10 00:58:53
pwipwi
版主


發表:68
回覆:629
積分:349
註冊:2004-04-08

發送簡訊給我
#20 引用回覆 回覆 發表時間:2004-11-10 03:33:23 IP:211.76.xxx.xxx 未訂閱
幫你修改了~檔案在 http://pwipwi.myweb.hinet.net/maze.zip 有兩三個地方有修過,就請你自行對照看看囉~ 還有順便提一點,
joen0000
一般會員


發表:47
回覆:47
積分:18
註冊:2004-11-07

發送簡訊給我
#21 引用回覆 回覆 發表時間:2004-11-10 04:51:35 IP:61.230.xxx.xxx 未訂閱
引言: 幫你修改了~檔案在 http://pwipwi.myweb.hinet.net/maze.zip 有兩三個地方有修過,就請你自行對照看看囉~ 還有順便提一點,>< face="Verdana, Arial, Helvetica"> 好猛喔大大 真是太感謝你ㄌ 讓我學了粉多ㄉ東西....O MY GOD 發表人 -
joen0000
一般會員


發表:47
回覆:47
積分:18
註冊:2004-11-07

發送簡訊給我
#22 引用回覆 回覆 發表時間:2004-11-10 04:54:30 IP:61.230.xxx.xxx 未訂閱
引言:
引言: 幫你修改了~檔案在 http://pwipwi.myweb.hinet.net/maze.zip 有兩三個地方有修過,就請你自行對照看看囉~ 還有順便提一點,>< face="Verdana, Arial, Helvetica"> 好猛喔大大 真是太感謝了 讓我學ㄌ比課本外還多的東西...o my god
joen0000
一般會員


發表:47
回覆:47
積分:18
註冊:2004-11-07

發送簡訊給我
#23 引用回覆 回覆 發表時間:2004-11-11 02:10:39 IP:61.230.xxx.xxx 未訂閱
引言: [quote] 幫你修改了~檔案在 http://pwipwi.myweb.hinet.net/maze.zip 有兩三個地方有修過,就請你自行對照看看囉~ 還有順便提一點,>< face="Verdana, Arial, Helvetica"> 那pwipwi大大那我要怎ㄇ把stack印在memo上 因為stack型態不是string 怎樣把他轉string或者有別ㄉ方法ㄋ.. 想ㄌ也蠻久ㄌ.也找過文章... 喔...大大.....Orz
joen0000
一般會員


發表:47
回覆:47
積分:18
註冊:2004-11-07

發送簡訊給我
#24 引用回覆 回覆 發表時間:2004-11-11 02:13:52 IP:61.230.xxx.xxx 未訂閱
引言:
引言: [quote] 幫你修改了~檔案在 http://pwipwi.myweb.hinet.net/maze.zip 有兩三個地方有修過,就請你自行對照看看囉~ 還有順便提一點,>< face="Verdana, Arial, Helvetica"> 那pwipwi大大那我要怎ㄇ把stack輸出在memo上 因為stack型態不是string 怎樣把他轉string或者有別ㄉ方法ㄋ.. 想ㄌ也蠻久ㄌ.也找過文章... 喔...大大.....Orz
pwipwi
版主


發表:68
回覆:629
積分:349
註冊:2004-04-08

發送簡訊給我
#25 引用回覆 回覆 發表時間:2004-11-12 02:25:02 IP:211.76.xxx.xxx 未訂閱
joen0000你好:     可以試試下面的碼,再運用到你的程式:  
#include 
using namespace std;
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    ostringstream outstream;
    outstream << "Hello World!!!" << endl;
    outstream << "This is stringstream" << endl;        Memo1->Lines->Text = outstream.str().c_str();    }
//---------------------------------------------------------------------------
 
joen0000
一般會員


發表:47
回覆:47
積分:18
註冊:2004-11-07

發送簡訊給我
#26 引用回覆 回覆 發表時間:2004-11-13 14:58:44 IP:61.230.xxx.xxx 未訂閱
引言: joen0000你好: 可以試試下面的碼,再運用到你的程式:
#include 
using namespace std;
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    ostringstream outstream;
    outstream << "Hello World!!!" << endl;
    outstream << "This is stringstream" << endl;        Memo1->Lines->Text = outstream.str().c_str();    }
//---------------------------------------------------------------------------
 
還是不會耶大大.... 我試這樣子寫
 #include 
using namespace std;
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    ostringstream outstream;
    for(int k=0;k outstream << stack[k] << endl;
    Memo1->Lines->Text = outstream.str().c_str();
   }
 
}
錯誤 哀哀是不是我ㄉ想法錯ㄌ... 還是少寫ㄍoperator+ 請pwipwi再次指導
joen0000
一般會員


發表:47
回覆:47
積分:18
註冊:2004-11-07

發送簡訊給我
#27 引用回覆 回覆 發表時間:2004-11-13 15:00:38 IP:61.230.xxx.xxx 未訂閱
引言: 還是不會耶大大.... 我是這樣子寫
 #include 
using namespace std;
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    ostringstream outstream;
    for(int k=0;k outstream << stack[k] << endl;
    Memo1->Lines->Text = outstream.str().c_str();
   }
 
}
錯誤 哀哀是不是我ㄉ想法錯ㄌ... 還是少寫ㄍoperator+ 請pwipwi再次指導 發表人 - joen0000 於 2004/11/13 15:02:34
pwipwi
版主


發表:68
回覆:629
積分:349
註冊:2004-04-08

發送簡訊給我
#28 引用回覆 回覆 發表時間:2004-11-13 15:41:29 IP:211.76.xxx.xxx 未訂閱
少寫了個operator 。 你應該是執行了以下的動作 stack[k] 123 其中 法運算是沒有定義的。
joen0000
一般會員


發表:47
回覆:47
積分:18
註冊:2004-11-07

發送簡訊給我
#29 引用回覆 回覆 發表時間:2004-11-13 17:28:52 IP:61.230.xxx.xxx 未訂閱
可是我好像沒有加到哩....  我又再次上傳我ㄉ檔案ㄌ  拜託拜託拜託拜託拜託拜託  大大再幫我看一次.......Orz http://delphi.ktop.com.tw/topic.php?TOPIC_ID=59470
pwipwi
版主


發表:68
回覆:629
積分:349
註冊:2004-04-08

發送簡訊給我
#30 引用回覆 回覆 發表時間:2004-11-14 16:20:45 IP:211.76.xxx.xxx 未訂閱
參考下面的碼~  
 
class Stack
{     public:
  friend std::ostream &operator << <>( std::ostream& os, const Stack& s);
   Stack(int maxstacksize=DefaultSize);
   Boolean isfull();
   Boolean isempty();
   void add(const keytype &);
   keytype* Delete(keytype &);       int top;
   keytype *stack_1;       int maxsize;
   //  加入以下這一行
   keytype& operator[](int index){stack_1[index];}
   };    
joen0000
一般會員


發表:47
回覆:47
積分:18
註冊:2004-11-07

發送簡訊給我
#31 引用回覆 回覆 發表時間:2004-11-14 18:23:39 IP:61.230.xxx.xxx 未訂閱
引言: 參考下面的碼~
 
class Stack
{     public:
  friend std::ostream &operator << <>( std::ostream& os, const Stack& s);
   Stack(int maxstacksize=DefaultSize);
   Boolean isfull();
   Boolean isempty();
   void add(const keytype &);
   keytype* Delete(keytype &);       int top;
   keytype *stack_1;       int maxsize;
   //  加入以下這一行
   keytype& operator[](int index){stack_1[index];}
   };    
挖........第一次看到最後一ㄍ不是分號ㄉ... pwipwi大大 加ㄉ這一樣是啥東東阿ˋ... 我想學會耶大大...拜託指導ㄌ..
[<<] [1] [2] [>>]
系統時間:2024-05-19 1:33:20
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!