在 c++ 中,如果包含标头,为什么我会收到'does not a name of type'错误?

In c++ if header is included why I got 'does not a name of type' error?

本文关键字:not does of 错误 type name 包含标 如果 c++ 为什么      更新时间:2023-10-16

我有data.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

我有enor.h

#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

我得到了'Student' does not a name a type,但为什么呢?我也尝试了如果Student小牛在enor.h,但也有这个错误。我该如何解决这个问题,为什么会这样?

您的student类的情况有所不同:

  1. class student - 小写s

  2. Student Current() const - 大写S