我在Google和Stak Overflow上研究了这个问题,但找不到答案。
我试图找出所有信息存储在.cpp文件扩展名中的内容。意思是,它只是编译的代码(意思是编译代码)?有一个目标文件吗?它中是否包含一个对象?它究竟是由什么组成的?
.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文件中使用该类。其中一个cpp文件将包含main()方法。