C++编译文件

标签 c++ compilation abstract-class

我有一个名为 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/

相关文章:

c++ - 对 `tesseract::TessBaseAPI::TessBaseAPI()' 的 undefined reference

c++ - boost::asio::ip::tcp::resolver::iterator 检查值是否为空

c++ - Makefile: "No rule to make target..."有多个工作目录

java - 什么时候必须使用接口(interface)而不是抽象类?

java - 如何更改 swig 生成的代理类中的特定方法实现?

c++ - 在 C++ 中使用 ioprio_set

C++ Functor 作为函数的输出参数

c++ - 为什么包含 .h 也会使 .cpp 源代码随之而来?

ios - 如何处理大型 Swift 项目?

java - 子类构造函数中的 super 有何作用?