-6

I have 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

And I have 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

And I got 'Student' does not a name a type, but why? I tried also if the Student calss is in enor.h, but also this error. how can I resolve this, and why is this?

Korte Alma
  • 168
  • 8
  • 1
    This is because you failed to include a [mcve] in your question. It's also possible it's because [you have a bad C++ teacher](https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice). – Sam Varshavchik Jun 09 '17 at 22:39
  • 3
    Uppercase/lowercase problem. You have defined a class named `student` but are trying to use `Student`. – R Sahu Jun 09 '17 at 22:40
  • 2
    As already mentioned, `using namespace std;` is bad, but doing that in a header is unacceptable. Please learn C++ from a good book, whatever you are doing now will not get you anywhere. – Baum mit Augen Jun 09 '17 at 22:45
  • Please carefully read [this answer](https://stackoverflow.com/a/1453605/721269) which explains how `using namespace std;` can result in code whose behavior changes unpredictably. [Here's](https://stackoverflow.com/questions/2712076/how-to-use-an-iterator/2712125) a case where just including your header could cause unrelated code to break while still compiling. – David Schwartz Jun 09 '17 at 22:58

1 Answers1

2

You have a difference in your case for your student class:

  1. class student - Lower case s

  2. Student Current() const - Upper case S

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Fantastic Mr Fox
  • 32,495
  • 27
  • 95
  • 175