2011-12-10 89 views
-1

私は、このような一般的なエラーに助けを求めることを憎むが、私はどのようなコンパイラが言うことは不足しているセミコロンや不定型で検索しようと2時間の私のコードを凝視して催促してきた:エラーC2146:構文エラー: ';'がありません。

エラーC2146:構文エラー:がありません ';'識別子 'history'の前..... .....
エラーC4430: 型指定子がない - が仮定されています。注:C++はサポートしていません default-int 1> c:\ users \ alex \ dropbox \ lab4 \ lab4 \ lab4 \ customer.h(49): エラーC4430:型指定子がない - 想定されています。注: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.hcustomer.hを含めるようにしてください。この場合、解決する必要がある循環インクルードがあります。 rentalhistory.hでは、customer.hの代わりにclass Customer;のような前方宣言を追加する必要があります。

その他:customer.hはなぜそれ自体を含めるようにしますか?

+0

ありがとう、sth。あなたは循環依存について正しいものでした。私は前方宣言を含めました。 .cppファイルに宣言されたクラスのヘッダーのみをインクルードしますか? – ShrimpCrackers

+0

はい、.cppファイルのヘッダーを含めて正しいことを行う必要があります。 – sth

関連する問題