简体   繁体   English

g ++编译错误基本对象构造

[英]g++ compile error basic object construction

I'm receiving the error: 我收到错误:

thing.cpp:5:1: error: ‘SquareThing’ does not name a type
 SquareThing::SquareThing()
 ^
compilation terminated due to -Wfatal-errors.
make: *** [thing.o] Error 1

my thing.h file: 我的thing.h文件:

#define THING_H_
#ifndef THING_H_
#include <vector>
#include <iostream>
class SquareThing{

public:
        SquareThing();
        //other functions
private:
    int something;
    //more members

};
#endif

Any my thing.cpp: 任何我的东西.cpp:

#include "thing.h"
#include <vector>
#include <iostream>
using namespace std;
SquareThing::SquareThing()
{
     something = 3;
}
//more functions below

This seems too rudimentary but I really can't seem to find the error. 这似乎太基本了,但我似乎找不到错误。 Any help is greatly appreciated. 任何帮助是极大的赞赏。

These two statements are backward: 这两个语句是向后的:

#define THING_H_
#ifndef THING_H_

You most certainly meant: 您最肯定的意思是:

#ifndef THING_H_
#define THING_H_

In the backward order, you were ensuring that the body of the header never kicked in, which isn't terribly useful. 按照向后的顺序,您要确保头文件的主体永远不会插入,这并不是非常有用。

You need to switch the order of your macros: 您需要切换宏的顺序:

#define THING_H_ // define the macro
#ifndef THING_H_ // if the macro is not defined (well, it is always defined...)

should be 应该

#ifndef THING_H_ // if the macro hasn't been defined ...
#define THING_H_ // ... define it

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM