# My c++ code should work, but UCLASS and class is throwing errors that can't be fixed

**URL:** <https://forums.unrealengine.com/t/my-c-code-should-work-but-uclass-and-class-is-throwing-errors-that-cant-be-fixed/364286>\
**Category:** C++\
**Tags:** errors, UClass, unreal-engine, UE4, CPP, question\
**Created:** [July 17, 2016, 2:47pm UTC](https://forums.unrealengine.com/t/my-c-code-should-work-but-uclass-and-class-is-throwing-errors-that-cant-be-fixed/364286 "2016-07-17T14:47:37Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthew\_BpBuds](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Matthew\_BpBuds](https://forums.unrealengine.com/u/Matthew_BpBuds)\
**Post date:** [July 17, 2016, 2:47pm UTC](https://forums.unrealengine.com/t/my-c-code-should-work-but-uclass-and-class-is-throwing-errors-that-cant-be-fixed/364286/1 "2016-07-17T14:47:37Z")

</div>

I get the error: “This declaration has no storage class or type specifier” in regards to the word UCLASS, and “class” returns “Expected a ;” I have retried this at least 10 times, to NO avail. What is wrong?

```
UCLASS(Blueprintable)
class CPPCUSTOMCHARTEST_API GetHelloWorld
{	
	GENERATED_BODY()
public:
	UFUNCTION(BlueprintPure, meta = (DisplayName = "Print Hello", Keywords = "Hello World"), Category = Game)
		static FText returnText();
	GetHelloWorld();
};
```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_4b3639a6](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_4b3639a6](https://forums.unrealengine.com/u/anonymous_user_4b3639a6)\
**Post date:** [July 17, 2016, 9:48pm UTC](https://forums.unrealengine.com/t/my-c-code-should-work-but-uclass-and-class-is-throwing-errors-that-cant-be-fixed/364286/2 "2016-07-17T21:48:34Z")

</div>

Hey 🙂

GetHelloWorld has to derive at least from UObject to use UClass.  
If should be an Actor (An Actual “Being” in the Scene) it has to derive from AActor

so adding:

```
: public UObject //or.. :public AActor

```

after GetHelloWorld should do the trick.

BUT:  
If it derives from UObject it has to have the prefix U (UGetHelloWorld)  
From AActor it has to have the prefic A (AGetHelloWorld)

Greetings

---

<div class="post-metadata">

**Author:** ![Matthew\_BpBuds](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Matthew\_BpBuds](https://forums.unrealengine.com/u/Matthew_BpBuds)\
**Post date:** [July 17, 2016, 9:52pm UTC](https://forums.unrealengine.com/t/my-c-code-should-work-but-uclass-and-class-is-throwing-errors-that-cant-be-fixed/364286/3 "2016-07-17T21:52:07Z")

</div>

THANK YOU. SO. MUCH. (Will test in a second)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_4b3639a6](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_4b3639a6](https://forums.unrealengine.com/u/anonymous_user_4b3639a6)\
**Post date:** [July 17, 2016, 9:55pm UTC](https://forums.unrealengine.com/t/my-c-code-should-work-but-uclass-and-class-is-throwing-errors-that-cant-be-fixed/364286/4 "2016-07-17T21:55:49Z")

</div>

No Problem.  
I hope it works for you 🙂

---

<div class="post-metadata">

**Author:** ![Matthew\_BpBuds](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Matthew\_BpBuds](https://forums.unrealengine.com/u/Matthew_BpBuds)\
**Post date:** [July 17, 2016, 10:16pm UTC](https://forums.unrealengine.com/t/my-c-code-should-work-but-uclass-and-class-is-throwing-errors-that-cant-be-fixed/364286/5 "2016-07-17T22:16:06Z")

</div>

It does not work still.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_4b3639a6](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_4b3639a6](https://forums.unrealengine.com/u/anonymous_user_4b3639a6)\
**Post date:** [July 17, 2016, 10:17pm UTC](https://forums.unrealengine.com/t/my-c-code-should-work-but-uclass-and-class-is-throwing-errors-that-cant-be-fixed/364286/6 "2016-07-17T22:17:24Z")

</div>

Can you show me you code?  
The whole .h file if possible 🙂

---

<div class="post-metadata">

**Author:** ![Matthew\_BpBuds](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Matthew\_BpBuds](https://forums.unrealengine.com/u/Matthew_BpBuds)\
**Post date:** [July 17, 2016, 10:33pm UTC](https://forums.unrealengine.com/t/my-c-code-should-work-but-uclass-and-class-is-throwing-errors-that-cant-be-fixed/364286/7 "2016-07-17T22:33:40Z")

</div>

I tried in a different file (because I got rid of the other one, thinking it was just a fluke) this is what I still have:

```
// Fill out your copyright notice in the Description page of Project Settings.

/**
 * 
 */

UCLASS(Blueprintable) //This declaration has no storage class or type specifier 
class TESTFORCODE_API UHello : public UObject //Expected a ;
{
	GENERATED_BODY()
public:
	UHello();
	~UHello();
};
```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_4b3639a6](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_4b3639a6](https://forums.unrealengine.com/u/anonymous_user_4b3639a6)\
**Post date:** [July 18, 2016, 7:27am UTC](https://forums.unrealengine.com/t/my-c-code-should-work-but-uclass-and-class-is-throwing-errors-that-cant-be-fixed/364286/8 "2016-07-18T07:27:07Z")

</div>

You still have to include the Hello.generated.h file

Just add

```
#include "Hello.generated.h"

```

In your Hello.cpp  
You have to:

```
#include "testforcode.h"

```

You probably have to generate a new Visual Studio Solution file by  
right Clicking on your .uproject file and click on “Generated Visual Studio Project Files”

After this you can build your Project again

Another question:  
Didn’t you use the Class Wizard from Unreal Editor?  
He generates all the dependencies one Class should have.

Greetings

---

<div class="post-metadata">

**Author:** ![Matthew\_BpBuds](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Matthew\_BpBuds](https://forums.unrealengine.com/u/Matthew_BpBuds)\
**Post date:** [July 18, 2016, 6:38pm UTC](https://forums.unrealengine.com/t/my-c-code-should-work-but-uclass-and-class-is-throwing-errors-that-cant-be-fixed/364286/9 "2016-07-18T18:38:24Z")

</div>

No matter how many times I generate the project files by right clicking on the .uproject, I never get the .generated.h files.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_4b3639a6](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_4b3639a6](https://forums.unrealengine.com/u/anonymous_user_4b3639a6)\
**Post date:** [July 18, 2016, 7:07pm UTC](https://forums.unrealengine.com/t/my-c-code-should-work-but-uclass-and-class-is-throwing-errors-that-cant-be-fixed/364286/10 "2016-07-18T19:07:48Z")

</div>

Then try to do the following:

Delete the solution file. Then go to you Binaries Folder and delete all files and directories in there (In mine is Win64 because I built my Project for that).

Then try to generate the solution files again.

Which errors do you get at the moment when trying to build??

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_b730fea1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_b730fea1](https://forums.unrealengine.com/u/anonymous_user_b730fea1)\
**Post date:** [July 18, 2016, 7:18pm UTC](https://forums.unrealengine.com/t/my-c-code-should-work-but-uclass-and-class-is-throwing-errors-that-cant-be-fixed/364286/11 "2016-07-18T19:18:24Z")

</div>

Use Build-\>Rebuild Solution in VS. Cause generated files being actually generated during build process. I’d also recommend you to close UE Editor before rebuilding.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_4b3639a6](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_4b3639a6](https://forums.unrealengine.com/u/anonymous_user_4b3639a6)\
**Post date:** [July 18, 2016, 7:25pm UTC](https://forums.unrealengine.com/t/my-c-code-should-work-but-uclass-and-class-is-throwing-errors-that-cant-be-fixed/364286/12 "2016-07-18T19:25:56Z")

</div>

Unfortunately rebuilding does not help everytime.  
I often had issues where the only way I could go on, where the steps I descriped above.

Greetings

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_b730fea1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_b730fea1](https://forums.unrealengine.com/u/anonymous_user_b730fea1)\
**Post date:** [July 18, 2016, 7:32pm UTC](https://forums.unrealengine.com/t/my-c-code-should-work-but-uclass-and-class-is-throwing-errors-that-cant-be-fixed/364286/13 "2016-07-18T19:32:26Z")

</div>

Your class should deriver from AActor or UObject. Also it should include some generated headers and so on.  
It’s kind a boring task to explain every aspect here, so the best solution for you should be making new class from Unreal Editor:

1. Start Unreal Editor.
2. In Content Browser open C++ Classes.
3. Choose folder you want your newly created class to be in.
4. Right click on free space and choose “New C++ Class…”
5. In a Choose Parent Class window click on checkbox in right top corner called “Show All Classes”
6. Type “UObject” in search field to be sure you are right. Or just:
7. Select Object in search results and click Next button.
8. Name your class and check desired location.

As a result, you’ll get already compiled, correctly written class.

Like this one:

MyNewObject.h:

```
// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "Object.h"
#include "MyNewObject.generated.h"

/**
 * 
 */
UCLASS()
class MYGAME_API UMyNewObject : public UObject
{
	GENERATED_BODY()

};

```

MyNewObject.cpp:

```
// Fill out your copyright notice in the Description page of Project Settings.

#include "MyGame.h"
#include "MyNewObject.h"

```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_b730fea1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_b730fea1](https://forums.unrealengine.com/u/anonymous_user_b730fea1)\
**Post date:** [July 18, 2016, 7:33pm UTC](https://forums.unrealengine.com/t/my-c-code-should-work-but-uclass-and-class-is-throwing-errors-that-cant-be-fixed/364286/14 "2016-07-18T19:33:15Z")

</div>

Well, then read my answer I’ve just published. 🙂

---

<div class="post-metadata">

**Author:** ![Matthew\_BpBuds](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Matthew\_BpBuds](https://forums.unrealengine.com/u/Matthew_BpBuds)\
**Post date:** [July 18, 2016, 7:35pm UTC](https://forums.unrealengine.com/t/my-c-code-should-work-but-uclass-and-class-is-throwing-errors-that-cant-be-fixed/364286/15 "2016-07-18T19:35:25Z")

</div>

Error MSB3073 The command ““C:\Program Files (x86)\Epic Games\4.12\Engine\Build\BatchFiles\Rebuild.bat” MyProject5Editor Win64 Development “C:\Users\matth\OneDrive\Documents\Unreal Projects\MyProject5\MyProject5.uproject” -waitmutex” exited with code -1.

---

<div class="post-metadata">

**Author:** ![Matthew\_BpBuds](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Matthew\_BpBuds](https://forums.unrealengine.com/u/Matthew_BpBuds)\
**Post date:** [July 18, 2016, 8:09pm UTC](https://forums.unrealengine.com/t/my-c-code-should-work-but-uclass-and-class-is-throwing-errors-that-cant-be-fixed/364286/16 "2016-07-18T20:09:53Z")

</div>

I did EXACTLY what you said, and it still throws a “Can’t read source file” error for the .generated.h file it makes.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_b730fea1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_b730fea1](https://forums.unrealengine.com/u/anonymous_user_b730fea1)\
**Post date:** [July 18, 2016, 8:21pm UTC](https://forums.unrealengine.com/t/my-c-code-should-work-but-uclass-and-class-is-throwing-errors-that-cant-be-fixed/364286/17 "2016-07-18T20:21:09Z")

</div>

It’s a Visual Studio error message. VS needs time to understand, whether there is a problem or not. Question is, what error being thrown at compile time in Output window?

---

<div class="post-metadata">

**Author:** ![Matthew\_BpBuds](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Matthew\_BpBuds](https://forums.unrealengine.com/u/Matthew_BpBuds)\
**Post date:** [July 18, 2016, 8:21pm UTC](https://forums.unrealengine.com/t/my-c-code-should-work-but-uclass-and-class-is-throwing-errors-that-cant-be-fixed/364286/18 "2016-07-18T20:21:29Z")

</div>

Actually, after numerous attempts, it seems to have accepted it, and hadn’t due to the project I had used.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_4b3639a6](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_4b3639a6](https://forums.unrealengine.com/u/anonymous_user_4b3639a6)\
**Post date:** [July 18, 2016, 8:47pm UTC](https://forums.unrealengine.com/t/my-c-code-should-work-but-uclass-and-class-is-throwing-errors-that-cant-be-fixed/364286/19 "2016-07-18T20:47:14Z")

</div>

Yeah exactly the thing I recommended 😃

But I wanted to explain all dependencies one class should have.  
When I first used Unreal there were many Errors and I didn’t know why, until I realized that the Naming Conventions etc. where essentially. (F before struct name, U before Object and/or Components A before Actor)  
Also other things like .generated.h and so on are things you have to know when using Unreal Engine, because the Compiler is not a help, when trying to find the error.

So I tried to show him all the things he has to be careful at.

But fortunately the problem is solved now 🙂

Good luck

Greetings

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_b730fea1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_b730fea1](https://forums.unrealengine.com/u/anonymous_user_b730fea1)\
**Post date:** [July 18, 2016, 9:18pm UTC](https://forums.unrealengine.com/t/my-c-code-should-work-but-uclass-and-class-is-throwing-errors-that-cant-be-fixed/364286/20 "2016-07-18T21:18:43Z")

</div>

You are right. It’s all important and your intentions are good. 🙂

If he’d like to get knowledge about all this aspects, he would have read Programming Guide section in Unreal Engine’s docs. But all he needs - is shortcut to God. And know what? That is normal, we are all humans. 🙂
