0

这是我目前收集的标题:

 #include "Header1.h"
 #include "BedAndMatress.h"
 #include "Sofa.h"
 #include "Table.h"
 #include iostream
 #include fstream
 #include iomanip 
 #include string
 #include cmath
 #include vector

using namespace std;


int main()

包含和命名空间 std 位在我的主文件和我的“函数定义.cpp”文件中。但是,编译器会抛出一些错误:

  e:\computing\coursework2\programme.cpp(2) : fatal error C1083: Cannot open include
 file: 'BedAndMatress.h': No such file or directory

最初我在 Header1.h 文件中定义了我的所有类,但它抱怨文件和类定义的意外结束,所以我决定将它们分开。该文件包含在项目中,所有其他文件似乎都在工作,所以我不确定发生了什么。我还创建了一个名为 Bed 的新头文件,但它有相同的错误,所以我更改了它,认为可能已经有一个具有该名称的标准文件(显然是长镜头)是否有最大数量的头文件?

此外,在类定义中,一些成员对象是字符串......

#ifndef CLASS_Bed
#define CLASS_Bed
//////BED
class Bed:public Item
{
string frame;
string frameColour;
string mattress;

public:

int Bed(int count);
int Bed(int count, int number, string name, string frm, string fclr, string mtres);
void count();
void printDetails();
}
#endif

但它不识别类型说明符。

error C2501: 'string' : missing storage-class or type specifiers

我应该包括字符串吗?我在某处读到这可能会导致问题,所以如果那不是解决方案,我应该如何进行?

太极Hx

4

4 回答 4

2

我应该包括字符串吗?我在某处读到这可能会导致问题,所以如果那不是解决方案,我应该如何进行?

你应该包括<string>. 您可能会读到不能放入using namespace std;标题,这是真的。但是,如果需要,包含标题并没有错。您需要限定string虽然的用途:

#ifndef CLASS_Bed
#define CLASS_Bed
//////BED
#include <string>
class Bed:public Item
{
std::string frame;
std::string frameColour;
std::string mattress;

public:

int Bed(int count);
int Bed(int count, int number, std::string name, std::string frm, std::string fclr, std::string mtres);
void count();
void printDetails();
};     //<-- note semi-colon here
#endif
于 2012-04-18T14:48:32.830 回答
1

问题是您在类定义中的右大括号后缺少分号。

于 2012-04-18T14:49:30.650 回答
0

最初我在 Header1.h 文件中定义了我的所有类,但它抱怨文件和类定义的意外结束,所以我决定将它们分开。

这是因为你忘了在类定义后加分号

class Bed:public Item
{
 ...
}; //notice the semicolon 

#endif
于 2012-04-18T14:53:39.950 回答
0

最初我在 Header1.h 文件中定义了我的所有类,但它抱怨文件和类定义的意外结束,所以我决定将它们分开。

这可能意味着您在某处错过了右括号( , 或)];如果它到达文件末尾而所有括号都没有关闭,编译器将给出该错误。但是,无论如何,将类放在单独的标头中是个好主意。}>

致命错误 C1083:无法打开包含文件:“BedAndMatress.h”:没有这样的文件或目录

这表示它找不到名为"BedAndMatress.h". 你有那个名字的文件吗?它是否与包含它的源文件位于同一目录中?如果不是,您是否在包含路径中指定目录?文件名的拼写是否完全一样,大写?

错误 C2501:“字符串”:缺少存储类或类型说明符

首先,您需要包含<string>以获取定义。然后你需要使用它的全名std::string。您可能很想放入using namespace std;头文件,但这是一个坏主意 - 在全局命名空间中转储名称可能会破坏包含头文件的其他文件。在源文件中这样做也不是一个好主意,但至少在那里损坏只会影响您自己的代码。

您还缺少 a;在类定义的末尾。

于 2012-04-18T15:08:58.623 回答