我正在从Java迁移到C++。看来C++使得在不同文件中声明类是很困难的。所以,我需要你的帮助,g ++找不到头文件
在我的main.cpp:
#include "Sphere.h"
using namespace std;
.....
...
..
int main(void) {
Sphere *earth = new Sphere(sphere_start ,sphere_end);
...
..
.
在我Sphere.h
class Sphere
{
public:
Sphere(int,int);
}
,并在我的Sphere.cpp
#include "Sphere.h"
using namespace std;
int sphere_start, sphere_end;
Sphere::Sphere (int a, int b)
{
sphere_start = a;
sphere_end = b;
}
void Sphere::render(int i)
{
....
..
.
}
这是我认为非常基本的代码会导致以下错误:
main.cpp:14:20: fatal error: Sphere.h: No such file or directory
compilation terminated.
为什么?
所有文件在同一目录 – 2012-01-05 00:38:50
遗憾的文件是不是在同一个目录。大声笑愚蠢我 – 2012-01-05 00:45:11
如何可以“调试”这个问题,当清楚所有头文件都已到位,所有必要的开发包安装和源文件引用正确的头文件路径,但编译器仍然无法找到头文件。 – 2014-01-10 20:28:20