这可能是也可能不是IDE特有的问题。在Code :: Blocks中获取范围错误
所以我做了一个使用Code :: Blocks的项目。在项目文件夹中有Main.cpp的,Person.h和Person.cpp:
// main.cpp
#include "Person.h"
int main()
{
int x = 1, y = 2, z = 3;
Person p = new Person(x, y, z);
}
我得到一个错误,指出人员和“p”在此范围内没有宣布。但是我在Person.h中声明了它们。我包含了Person.h头文件。那么,那里的代码也应该在Main中,对吧?
这里是Person.h的内容:
#ifndef PERSON_H
#define PERSON_H
class Person
{
public:
Person();
Person(int, int, int);
private:
int x, y, z;
};
#endif
你能证明什么的'Person.h'? – ryrich