2011-03-04 97 views
1

ISBN.cpp:8: error: 'ISBN' has not been declared類未聲明? (C++)

ISBN.cpp:8: error: ISO C++ forbids declaration of 'ISBN' with no type ISBN.cpp: In function 'int ISBN()':

ISBN.cpp:9: error: 'area' was not declared in this scope

ISBN.cpp:10: error: 'publisher' was not declared in this scope

ISBN.cpp:11: error: 'title' was not declared in this scope ISBN.cpp:12: error: 'checkdigit' was not declared in this scope ISBN.cpp:13: error: 'isbnStr' was not declared in this scope

8號線至14是:

ISBN::ISBN() { 
area = NULL; 
publisher = NULL; 
title = NULL; 
checkdigit = NULL; 
isbnStr = NULL; 
} 

他們都在頭部聲明:

class ISBNPrefix; 
class ISBN 
{ 
private: 
int area; 
int publisher; 
int title; 
char checkdigit; 
char* isbnStr[10]; 
public: 
ISBN(); 
... 

任何想法,這可能是這裏的問題?我猜測它簡單的東西我錯過了。

+1

您可以嘗試將格式整理出來嗎?很難遵循全部在一行上的代碼。縮進所有代碼至少4個空格字符,它應該都會更好。 – 2011-03-04 21:54:48

+0

盲目猜測:循環頭依賴經常會導致此問題,因爲多重保護導致循環頭第二次迭代包含失敗默默。 – 2011-03-04 21:56:51

+2

你做過##包含在ISBN.cpp中的頭文件,對不對? – aschepler 2011-03-04 21:58:24

回答

8

這看起來很明顯,但是您是否仔細檢查過您是否在ISBN.cpp中包含頭文件?也許,你不小心使用了與兩個頭文件包括相同的預處理常量,導致文件的ISBN聲明被有效忽略?您發佈的代碼片段對我來說看起來不錯...

+1

+1「意外地使用了相同的預處理器常量」我看過的次數。 – Tony 2011-03-04 22:05:47