即使最简单的类不编译,“尚未被声明 [英] Even the simplest class doesn't compile, "has not been declared
本文介绍了即使最简单的类不编译,“尚未被声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
好的,这真的很烦人。我有(几乎)最简单的类可能。两个文件:a.cpp和ah
ah:
OK, this is really annoying. I have the (almost) simplest class possible. Two files: a.cpp and a.h a.h:
#ifdef A_H
#define A_H
class a{
public:
a();
};
#endif
和a.cpp
#include "a.h"
a::a(){
}
但它不会编译:
g ++ a.cpp a.cpp: 3:错误:'a'没有
已声明
g++ a.cpp a.cpp:3: error: ‘a’ has not
been declared
显然,我做错了,
推荐答案
p>因为
#ifdef A_H
需要
#ifndef A_H
注意n,如果未定义。
编译代码,如果A_H被定义,它不是,因为你只定义它在下一行。
The former will only compile the code if A_H is defined, which it isn't since you only define it on the next line.
这篇关于即使最简单的类不编译,“尚未被声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文