Kyle
Kyle

Reputation: 23

Issues with declaring enum

I'm getting an error when trying to declare an enum. It says the identifier is undefined, but I am including the applicable file where it was defined. (This is my first coding class so sorry in advance). Where am I going wrong? And how do I pass the enum to a constructor?

// in degree.h file

#ifndef Student_h
#define Student_h

#pragma once

enum class DegreeProgram { program1, program2, program3 };

#endif


// in student.h file

#ifndef Student_h
#define Student_h

#pragma once

#include "degree.h"

class Student {

private:
   DegreeProgram program;
};

#endif

Upvotes: 1

Views: 84

Answers (1)

user12002570
user12002570

Reputation: 1

The problem is that you are using the same name Student_h in both of the include guards inside degree.h and student.h.

To solve this change the name of the include guards inside degree.h from Student_h to DEGREE_H as shown below:

degree.h

//------vvvvvvvv---->changed from Student_h to DEGREE_H
#ifndef DEGREE_H
#define DEGREE_H


enum class DegreeProgram { program1, program2, program3 };

#endif

Demo

Upvotes: 2

Related Questions