2012-08-30 68 views
0

我有一個名爲LibItem的抽象基類,以及兩個名爲Book和DVD的繼承類。我爲每個類創建了.h和.cpp文件。C++編譯文件

我現在想做一些代碼在主要使用這些文件。

目前,我只是'包括'我的主要代碼頂部的.h文件。 這不起作用。

我需要在使用它們之前編譯這些文件嗎?如果是這樣,我該怎麼做?

UPDATE

這裏是我的代碼:

//--------------------------------------------------------------------------- 

#ifndef BookH 
#define BookH 

class Book : public LibItem 
{ 
public: 
    Book(const std::string&, const std::string&, const std::string&, const std::string&, const std::string&, const std::string&, const std::string&); 
    void setISBN(const std::string&); 
    std::string getISBN(); 
    void PrintDetails(); 

private: 
    Book(); 
    std::string ISBN; 

}; 

//--------------------------------------------------------------------------- 
#endif 

我收到以下錯誤:

[BCC32 Error] Book.h(7): E2303 Type name expected 
[BCC32 Error] Book.h(9): E2090 Qualifier 'std' is not a class or namespace name 
[BCC32 Error] Book.h(9): E2293) expected 
[BCC32 Error] Book.h(10): E2090 Qualifier 'std' is not a class or namespace name 

我可以請有一些幫助這些錯誤?

+0

一般而言,是的,以及如何取決於您的編譯器和/或建立系統。 – juanchopanza

+2

告訴我們您使用的是哪一個構建系統或編譯器 – fasked

+0

我正在使用C++ Builder。我有的文件是LibItem.h,LibItem.cpp,Book,h,Book.cpp,DVD.h,DVD.cpp –

回答

1

您必須包含all.h文件,其中包含要在主文件中使用的聲明。此外,您必須將所有.cpp文件添加到您的項目/ makefile/etc以編譯它,因爲.h文件不是編譯單元...