2014-05-05 13 views
0

我知道這方面有很多問題,但是我檢查了我的程序中常見的錯誤,而且我似乎找不到任何錯誤。另一個「ISO C++禁止聲明」錯誤

我得到這些錯誤對我的拷貝構造函數在一個文件strlist.cpp的第一行:

ISO C++禁止的「Strlist」聲明沒有類型[-fpermissive] 沒有「廉政StrList: :Strlist(常量StrList &)」類的成員函數聲明爲 'StrList'

下面是部分:

/* copy constructor */ 
40 StrList::Strlist(const StrList& rhs) 
41 { 
42 intitList(&list); 
43 Struct Node *current = (rhs.list).head; 
44 while(current != NULL){ 
45  AddFront(*(const MyString *)current->data); 
46  current = current->next; 
47 } 
48 reverse(); 
49 } 

這裏是我的頭文件拷貝構造函數:

5 #ifndef __STRLIST_H__ 
    6 #define __STRLIST_H__ 
11 
12 #include "mystring.h" 
13 #include "stdio.h" 
14 #include "stdlib.h" 

20 
21 extern "C" { 
22 #include "mylist.h" 
23 } 
24 
25 class StrList { 
26 
27  public: 
(......................) 
40 
41   /*copy constructor */ 
42   StrList(const StrList& rhs); 
(..................) 
105 }; 
106 
107 #endif 

我在strlist.cpp中包含了strlist.h,所以我無法弄清楚這有什麼問題。

謝謝!

+4

C++是區分大小寫的。您還使用[保留標識符](http://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-a-c-identifier)。 – chris

+1

'struct node * current =(rhs.list).head;'你確定'Struct'應該大寫? – Brandon

+1

即使是小寫字母,它也沒有任何用處。 – chris

回答

2

ISO C++禁止的「Strlist」聲明無類型

StrList::Strlist(const StrList& rhs) 
//  ^ 

你應該額外小心讀取錯誤消息時,編譯器正在努力幫助您!

+1

「編譯器試圖幫助你」 - 錯誤信息有點奇怪,因爲它沒有說StrList類沒有名爲Strlist的類成員。我認爲Visual C++曾經給過這種更有用的錯誤消息。 – tinlyx

+0

它說:'在類'StrList''中聲明的'no int StrList :: Strlist(const StrList&)'成員函數這是一個開始..它可能更糟糕..例如:'template'錯誤。編譯器顯示你是誰的老闆;) – Brandon

+0

@TingL:語言是複雜的,編譯器將無法給你一個精確的描述,這更多的是仔細閱讀它告訴你的理由。在這種情況下,從用戶代碼'Strlist'和沒有'StrList :: Strlist'成員函數的事實是相當有用的。不是嗎?它不是說* StrList類沒有叫做'Strlist' *的類成員? –

2

簡單地改變StrList::StrlistStrList::StrList作爲第一種方式將不會被提及的構造(名單上的部分錯誤的情況下)

+0

我很困惑那些東西不一樣嗎? – user146303

+0

@ user146303 nope,你在源文件中放一點L而不是大寫; case在C++中很重要! – CoffeeandCode

+0

啊我不敢相信有多少錯別字我沒有注意到。謝謝! – user146303

相關問題