Enum in c++

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.

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.

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

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

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

@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

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.

What do you have in your .cpp file?

I have deleted the CPP file.

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.

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. :wink:

1 Like

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

Looking at uproperty specifiers, 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.

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.