我有一个名为 LibItem 的抽象基类,以及两个名为 Book 和 DVD 的继承类。我已经为每个类制作了 .h 和 .cpp 文件。
我现在想在 main 中编写一些代码来使用这些文件。
目前,我只是在主代码的顶部“包含”.h 文件。 这是行不通的。
我需要在使用前编译这些文件吗?如果是这样,我该怎么做?
更新
这是我的代码:
//---------------------------------------------------------------------------
#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
我可以帮忙解决这些错误吗?
最佳答案
您必须包含 all.h 文件,其中包含您要在主文件中使用的声明。此外,您必须将所有 .cpp 文件添加到您的项目/makefile/etc 中才能编译它,因为 .h 文件不是编译单元...
关于C++编译文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12190851/