C++ 在c++;如果包含标题,则说明我获得';没有类型为';错误
我有C++ 在c++;如果包含标题,则说明我获得';没有类型为';错误,c++,C++,我有数据。h: #ifndef DATA_H_INCLUDED #define DATA_H_INCLUDED #include <vector> #include <string> #include <iostream> using namespace std; class student{ public: string id; int points [6] = {0,0,0,0,0,0}; }; #end
数据。h
:
#ifndef DATA_H_INCLUDED
#define DATA_H_INCLUDED
#include <vector>
#include <string>
#include <iostream>
using namespace std;
class student{
public:
string id;
int points [6] = {0,0,0,0,0,0};
};
#endif // DATA_H_INCLUDED
#ifndef ENOR_H_INCLUDED
#define ENOR_H_INCLUDED
#include <fstream>
#include <vector>
#include <string>
#include <iostream>
#include "data.h"
using namespace std;
enum status{norm,abnorm};
class enor{
public:
/*some voids*/
Student Current() const { return elem; }
student elem;
private:
/*some voids*/
};
#endif // ENOR_H_INCLUDED
我得到了
“学生”不是一个名字,而是一个类型,但为什么呢?如果学生
计算器在nor.h
中,我也尝试了,但也出现了此错误。我怎样才能解决这个问题,为什么会这样?对于你的学生
班级,你的情况有所不同:
class-student
-小写s
Student Current()const
-大写S
这是因为你没有在问题中加入a。也有可能是因为.大写/小写的问题。您已经定义了一个名为student
的类,但正在尝试使用student
不好,但在标头中这样做是不可接受的。请从一本好书中学习C++,不管你现在做什么都不能让你在任何地方。请仔细阅读,解释如何使用代码空间STD代码< >code>会导致代码的行为发生不可预测的变化。在这种情况下,仅包含标头可能会导致不相关的代码在编译时中断。