g++编译错误基本对象构造
g++ compile error basic object construction
我收到错误:
thing.cpp:5:1: error: ‘SquareThing’ does not name a type
SquareThing::SquareThing()
^
compilation terminated due to -Wfatal-errors.
make: *** [thing.o] Error 1
我的thing.h文件:
#define THING_H_
#ifndef THING_H_
#include <vector>
#include <iostream>
class SquareThing{
public:
SquareThing();
//other functions
private:
int something;
//more members
};
#endif
我的任何东西.cpp:
#include "thing.h"
#include <vector>
#include <iostream>
using namespace std;
SquareThing::SquareThing()
{
something = 3;
}
//more functions below
这看起来太初级了,但我似乎真的找不到错误。非常感谢您的帮助。
这两个语句是向后的:
#define THING_H_
#ifndef THING_H_
你的意思当然是:
#ifndef THING_H_
#define THING_H_
在向后的顺序中,您确保标头的正文永远不会进入,这并不是很有用。
您需要切换宏的顺序:
#define THING_H_ // define the macro
#ifndef THING_H_ // if the macro is not defined (well, it is always defined...)
应该是
#ifndef THING_H_ // if the macro hasn't been defined ...
#define THING_H_ // ... define it
相关文章:
- 我可以将一个用clang c++11编译的对象与另一个用c++17编译的对象链接起来吗
- std::vector::p ush_back() 不会在 MSVC 上编译具有已删除移动构造函数的对象
- 是否可以在编译时初始化对象的 C 样式函数指针,以便它调用对象的成员函数?
- 如何制作一个作为类对象并具有编译时大小的数组?
- 由于缺少类模板,NVCC 编译面向对象代码时出现问题
- 编译时生成应在构造函数中创建的非 constexpr 对象数组
- 仅为从某种语言编译的对象添加链接库?
- 确保在编译期间仅同时使用来自同一工厂的对象
- 编译错误:临时对象构造函数中缺少参数
- 将 std::variant 与 gmock 1.8 对象一起使用时编译错误
- CMake + Qt,moc 编译失败,无法实现 QMetaObject 方法(编译器找不到基本 ui 对象的标头?
- 混合单独编译的对象
- 运行程序时找不到共享对象库,但在编译过程中链接了它
- 编译问题 C++ 同时,尝试通过调用另一个对象中的成员函数来创建 std:: 线程
- 初始化不可移动对象数组:为什么这样的代码无法在 GCC 上编译?
- C++对象文件和程序文件组合编译的 Bashrc 别名
- 将TopoDS_Face对象分配给其子对象编译没有错误,但我有 3 个 valgrind 错误
- 是否为每个C++对象编译了多个成员函数?
- c++LogFile对象编译错误
- 为派生类的每个对象编译的vftable