2011-12-10 145 views
-1

我不喜歡求人這樣一個常見的錯誤,但我一直在盯着我的代碼慫恿了兩個小時試圖找到編譯器說什麼是缺少分號和未指定類型:錯誤C2146:語法錯誤:缺少';'

錯誤C2146:語法錯誤:缺少';'在標識符'history'之前.....:
錯誤C4430: 缺少類型說明符 - int假定。注意:C++不支持 default-int 1> c:\ users \ alex \ dropbox \ lab4 \ lab4 \ lab4 \ customer.h(49): 錯誤C4430:缺少類型說明符 - int假定。注意:C++不 支持默認int

#pragma once 

#include <string> 
using std::string; 
#include "customerdata.h" 
#include "rentalhistory.h" 
#include "item.h" 
#include "customer.h" 
/*--------------------------------------------------------------------------- 
Purpose: class Customer contains methods to grab information about a customer, 
such as their id number, address, phone number (stored in class CustomerData). 
It also contains methods that will allow access to information about a 
customer’s rental history (stored in class RentalHistory). 

CONSTRUCTION: 
(1) empty construction. (2) name and id (3) with information provided by 
CustomerData object. 
--------------------------------------------------------------------------- */ 
class Customer 
{ 
public: 
    Customer(); 
    Customer(const Customer &); 
    Customer(string, string, int); 
    Customer(const CustomerData &); 
    ~Customer(); 

    // get customer's first name. 
    string getFirstName() const; 

    // get customer's last name. 
    string getLastName() const; 

    // get customer's id number 
    int getIdNum() const; 

    // add a movie to customer's rental history 
    void addMovie(Item *&, string code); 

    // checks to see if it is a valid customer 
    bool isValidCustomer(); 

    // prints the customer's rental history 
    void printHistory() const; 

    Customer & operator=(Customer &rhs); 


private: 
    CustomerData data; // object that contains customer's information 
    RentalHistory history; // object that contains customer's rental history 
}; 
+0

看起來你沒有定義'RentalHistory'。我們可以看到您的標題嗎? – Mysticial

+2

錯誤可能在customerdata.h,rentalhistory.h,item.h或customer.h中。更簡化您的代碼,以便我們可以實際編譯它並自行嘗試。閱讀http://sscce.org –

+0

David Grayson,感謝您的鏈接。下次我發帖時我會準備一份SSCCE – ShrimpCrackers

回答

5

該錯誤消息指示該編譯器無法識別RentalHistory作爲一種類型。如果在包含的rentalhistory.h中正確定義類型,則此類問題的最常見原因將是循環依賴性。

是否rentalhistory.h嘗試包括customer.h?在這種情況下,您需要通知您需要解決的問題。在rentalhistory.h中,您很可能必須添加前向聲明,如class Customer;而不是包含customer.h

另外:爲什麼customer.h試圖包括自己?

+0

謝謝,你對循環依賴關係是正確的。我已經包含了前向聲明。我是否只包含我在.cpp文件中聲明的類的標題? – ShrimpCrackers

+0

是的,包括.cpp文件中的標題應該做正確的事情。 – sth