【问题标题】:What kind of information is stored in a .cpp file extension? [closed].cpp 文件扩展名中存储了哪些信息? [关闭]
【发布时间】:2018-06-22 10:55:33
【问题描述】:

我在 Google 和 Stak Overflow 上研究了这个问题,但找不到答案。

我试图找出所有信息都存储在 .cpp 文件扩展名中。意思是,它只是已经编译的代码(意思是编译的代码)吗?里面有目标文件吗?它是否包含一个对象?它究竟是由什么组成的?

【问题讨论】:

  • 是c++源代码
  • 我投票决定将此问题作为题外话结束,因为没有努力寻找答案。
  • 它只是一个包含源代码的纯文本文件。
  • 我在 Stack Overflow 或 Google 上找不到这个问题的答案:google.com/…
  • 好的,谢谢。我以为不仅仅是源代码,比如编译代码,还是可执行代码?

标签: c++ file


【解决方案1】:

.h 通常有类定义(代码)

#ifndef CLASS_T_H
#define CLASS_T_H

class class_t {
public:
    class_t();
    class_t(const class_t& o);

    ~class_t();

    class_t& operator=(const class_t& o);

private:

};

#endif

而.cpp通常有类实现(代码)

#include "class_t.h"

class_t::class_t() {

}

class_t::class_t(const class_t& o) {

}

class_t::~class_t() {

}

class_t& class_t::operator=(const class_t& o) {
    return *this;
}

您可以通过包含 .h 文件并将 cpp 文件编译成二进制可执行文件,在另一个 .cpp 文件中使用 class_t。其中一个 cpp 文件将包含您的 main() 方法。

【讨论】:

  • 那么,也许我想多了,那它只是源代码?
  • 是的......
  • @SeanV 过度思考。按照惯例,cpp 是未编译的实现源代码。
  • 是的,按照惯例。我打算将其添加到答案中,但决定反对
  • @SeanV 以下是所有部分如何交互并转化为程序的一个很好的简要说明:How does the compilation/linking process work?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-21
  • 2014-01-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多