# Enum in c++

**URL:** <https://forums.unrealengine.com/t/enum-in-c/477778>\
**Category:** C++\
**Tags:** c-build, unreal-engine, question, CPP\
**Created:** [January 25, 2021, 8:54pm UTC](https://forums.unrealengine.com/t/enum-in-c/477778 "2021-01-25T20:54:48Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![MRSagor949](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MRSagor949](https://forums.unrealengine.com/u/MRSagor949)\
**Post date:** [January 25, 2021, 8:54pm UTC](https://forums.unrealengine.com/t/enum-in-c/477778/1 "2021-01-25T20:54:48Z")

</div>

Hello, I’m new to c++. I’m a blueprint programmer. Now I’m trying to convert my blueprint project into c++. But I have got a lot of errors at startup. When I am creating enum with none c++ class then write this code it’s given me a lot of error. Please Check my code And help me. I want to make an enum Library. but it’s not working.

```
#pragma once

#include "CoreMinimal.h"
#include "MRSEnumLibrary.generated.h"

UENUM(BlueprintType)
enum class EGait : uint8
{
	Walking,
	Running,
	Sprinting,
};

```

I don’t know what is the problem.

---

<div class="post-metadata">

**Author:** ![Shadowriver](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Shadowriver](https://forums.unrealengine.com/u/Shadowriver)\
**Post date:** [January 25, 2021, 9:46pm UTC](https://forums.unrealengine.com/t/enum-in-c/477778/2 "2021-01-25T21:46:48Z")

</div>

Can you show the error?  
One thing i notice you have comma at the end of enum list, comma should only separate enum items not end each of them.

---

<div class="post-metadata">

**Author:** ![Alekann01](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Alekann01](https://forums.unrealengine.com/u/Alekann01)\
**Post date:** [January 26, 2021, 3:56pm UTC](https://forums.unrealengine.com/t/enum-in-c/477778/3 "2021-01-26T15:56:17Z")

</div>

Hi MRSagor949

You do not need the “class” keyword.

Example:

```
UENUM(BlueprintType)
enum EMyEnum
{
       label1,
       label2,
       label3
};

```

To use your enum in blueprints

```
UPROPERTY(BlueprintReadWrite)
TEnumAsByte<EMyEnum> enumVariable;

```

Hope this helps.

Alex

---

<div class="post-metadata">

**Author:** ![PhilBax](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@PhilBax](https://forums.unrealengine.com/u/PhilBax)\
**Post date:** [January 26, 2021, 4:00pm UTC](https://forums.unrealengine.com/t/enum-in-c/477778/4 "2021-01-26T16:00:09Z")

</div>

Enum classes are certainly not required, but they are the “new” enums in C++, and very much recommended.

---

<div class="post-metadata">

**Author:** ![Alekann01](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Alekann01](https://forums.unrealengine.com/u/Alekann01)\
**Post date:** [January 26, 2021, 4:46pm UTC](https://forums.unrealengine.com/t/enum-in-c/477778/5 "2021-01-26T16:46:50Z")

</div>

@PhilBax Absolutely true.

Since MRSagor949 is new to C++, I just provided a quick easy example of using an enum with blueprints.

@MRSagor949 I tested your code (with the extra comma) and it compiles and executes fine. Can you provide what the exact error you’re receiving is? I have a suspicion something else is causing your problem.

Thanks

Alex

---

<div class="post-metadata">

**Author:** ![MRSagor949](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MRSagor949](https://forums.unrealengine.com/u/MRSagor949)\
**Post date:** [January 26, 2021, 5:29pm UTC](https://forums.unrealengine.com/t/enum-in-c/477778/6 "2021-01-26T17:29:37Z")

</div>

Brother, it still gets a lot of errors with using class and without using class. I don’t why this is happening. Please check my errors and help me.

 ![328161-screenshot-2.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/f/0/2f08ea6690cfa74a716e0445cd6fb0ebdb510f8f.png)

---

<div class="post-metadata">

**Author:** ![MRSagor949](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MRSagor949](https://forums.unrealengine.com/u/MRSagor949)\
**Post date:** [January 26, 2021, 5:39pm UTC](https://forums.unrealengine.com/t/enum-in-c/477778/7 "2021-01-26T17:39:53Z")

</div>

I try all the methods to create an enum Library.But it’s not working.

 ![328130-screenshot-3.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/5/a/65a2b64502cc5d4c3744003fba219645c6d1b128.png)

---

<div class="post-metadata">

**Author:** ![Alekann01](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Alekann01](https://forums.unrealengine.com/u/Alekann01)\
**Post date:** [January 26, 2021, 5:51pm UTC](https://forums.unrealengine.com/t/enum-in-c/477778/8 "2021-01-26T17:51:41Z")

</div>

What do you have in your .cpp file?

---

<div class="post-metadata">

**Author:** ![MRSagor949](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MRSagor949](https://forums.unrealengine.com/u/MRSagor949)\
**Post date:** [January 26, 2021, 6:35pm UTC](https://forums.unrealengine.com/t/enum-in-c/477778/9 "2021-01-26T18:35:04Z")

</div>

I have deleted the CPP file.

---

<div class="post-metadata">

**Author:** ![MRSagor949](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MRSagor949](https://forums.unrealengine.com/u/MRSagor949)\
**Post date:** [January 26, 2021, 6:36pm UTC](https://forums.unrealengine.com/t/enum-in-c/477778/10 "2021-01-26T18:36:52Z")

</div>

I want to make an enum library. just I want to access the enum from other CPP file. So, I just need the header file.

---

<div class="post-metadata">

**Author:** ![PhilBax](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@PhilBax](https://forums.unrealengine.com/u/PhilBax)\
**Post date:** [January 26, 2021, 6:51pm UTC](https://forums.unrealengine.com/t/enum-in-c/477778/11 "2021-01-26T18:51:49Z")

</div>

You may have deleted it from the Visual Studio project, but the file is still there.

Look at all of your errors. Look at the “File” column. All of those errors are from your cpp.

Open up Explorer, find the cpp file, and delete it there.

I’ve done the same thing myself. 😉

---

<div class="post-metadata">

**Author:** ![MRSagor949](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MRSagor949](https://forums.unrealengine.com/u/MRSagor949)\
**Post date:** [January 26, 2021, 9:22pm UTC](https://forums.unrealengine.com/t/enum-in-c/477778/12 "2021-01-26T21:22:52Z")

</div>

I didn’t delete my cpp file. After compile it’s gives me 4094 errors

 ![328185-screenshot-4.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/9/7/497f69a198921e11727d504ae622d0034ffbcc26.png)

---

<div class="post-metadata">

**Author:** ![PhilBax](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@PhilBax](https://forums.unrealengine.com/u/PhilBax)\
**Post date:** [January 26, 2021, 10:40pm UTC](https://forums.unrealengine.com/t/enum-in-c/477778/13 "2021-01-26T22:40:18Z")

</div>

Looking at [uproperty specifiers](https://docs.unrealengine.com/en-US/ProgrammingAndScripting/GameplayArchitecture/Properties/Specifiers/index.html), I don’t see BlueprintType as an option. I’m not sure where that came from, and it looks like that type is undefined (see the second error in your file).

Once that’s fixed, I suspect it will generate a “.generated.h” for you. I know it will generate one if your header has a UCLASS or a USTRUCT. It may not for just UENUMS, though.

If you’re still having the error, try commenting-out that include.

---

<div class="post-metadata">

**Author:** ![MRSagor949](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MRSagor949](https://forums.unrealengine.com/u/MRSagor949)\
**Post date:** [January 26, 2021, 11:21pm UTC](https://forums.unrealengine.com/t/enum-in-c/477778/14 "2021-01-26T23:21:03Z")

</div>

A lot of thanks to you. I have found the solution. there must include a cpp file, After compile complete then we can delete the CPP file. otherwise, it will give you these types of errors.
