# Why does one of my declarations produce an error, while its twin works fine?

**URL:** <https://forums.unrealengine.com/t/why-does-one-of-my-declarations-produce-an-error-while-its-twin-works-fine/327456>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [August 3, 2015, 5:26am UTC](https://forums.unrealengine.com/t/why-does-one-of-my-declarations-produce-an-error-while-its-twin-works-fine/327456 "2015-08-03T05:26:23Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![HInoue](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@HInoue](https://forums.unrealengine.com/u/HInoue)\
**Post date:** [August 3, 2015, 5:26am UTC](https://forums.unrealengine.com/t/why-does-one-of-my-declarations-produce-an-error-while-its-twin-works-fine/327456/1 "2015-08-03T05:26:23Z")

</div>

I have several custom subclasses of ActorComponent that I’m trying to instantiate on my ACharacter at runtime. I’m using identical syntax to declare and initialize them, but one works perfectly and the other produces a compiler error.

Both classes are included in the header, and declared in the class dec:

```
#include "Combat.h"
#include "Perception.h"

UCLASS()
class LearningProject_API ACharacter : public ABaseCharacter
{
	GENERATED_BODY()
public:
	UCombat* characterCombat;
	UPerception* characterPerception;
}

```

UCombat\*'s declaration works fine, but UPerception’s dec produces two sets of the same errors: “missing ; before \*”, and “missing type specifier- int assumed”. I can make this error go away by changing the last line to this:

```
class UPerception* characterPerception;

```

But it weirds me out that identical syntax is producing different results, and I’d rather not proceed without understanding the root behavior.

---

<div class="post-metadata">

**Author:** ![happyhorror\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@happyhorror\_1](https://forums.unrealengine.com/u/happyhorror_1)\
**Post date:** [August 3, 2015, 5:56am UTC](https://forums.unrealengine.com/t/why-does-one-of-my-declarations-produce-an-error-while-its-twin-works-fine/327456/2 "2015-08-03T05:56:38Z")

</div>

Hi,

seems your class are character based and i don’t sure why it’s miss some parts, when i did my class in 4.8.3 it’s

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

#pragma once

#include "GameFramework/Character.h"
#include "MyCharacter.generated.h"

UCLASS()
class LIGHTARRAY_API AMyCharacter : public ACharacter
{
	GENERATED_BODY()

public:
	// Sets default values for this character's properties
	AMyCharacter();

	// Called when the game starts or when spawned
	virtual void BeginPlay() override;
	
	// Called every frame
	virtual void Tick( float DeltaSeconds ) override;

	// Called to bind functionality to input
	virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override;

};

```

---

<div class="post-metadata">

**Author:** ![HInoue](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@HInoue](https://forums.unrealengine.com/u/HInoue)\
**Post date:** [August 3, 2015, 6:06am UTC](https://forums.unrealengine.com/t/why-does-one-of-my-declarations-produce-an-error-while-its-twin-works-fine/327456/3 "2015-08-03T06:06:11Z")

</div>

I have the class constructor and everything as well, I just elided them from the sample as I assumed they weren’t relevant- if I included the entire character header, it would be hundreds of lines.

---

<div class="post-metadata">

**Author:** ![happyhorror\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@happyhorror\_1](https://forums.unrealengine.com/u/happyhorror_1)\
**Post date:** [August 3, 2015, 6:19am UTC](https://forums.unrealengine.com/t/why-does-one-of-my-declarations-produce-an-error-while-its-twin-works-fine/327456/4 "2015-08-03T06:19:57Z")

</div>

do you mean template code take extra space or there’re hundreds of error lines?

i can’t find UCombat’s declaration in installed engine and source code folders, are you sure you have such file?

---

<div class="post-metadata">

**Author:** ![HInoue](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@HInoue](https://forums.unrealengine.com/u/HInoue)\
**Post date:** [August 3, 2015, 6:22am UTC](https://forums.unrealengine.com/t/why-does-one-of-my-declarations-produce-an-error-while-its-twin-works-fine/327456/5 "2015-08-03T06:22:06Z")

</div>

I mean that my character file is very long, and most of it is unrelated to the compiler error. UCombat and UPerception are classes I wrote, they are subclasses of UActorComponent proprietary to my system, not part of unreal’s API.

---

<div class="post-metadata">

**Author:** ![happyhorror\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@happyhorror\_1](https://forums.unrealengine.com/u/happyhorror_1)\
**Post date:** [August 3, 2015, 6:37am UTC](https://forums.unrealengine.com/t/why-does-one-of-my-declarations-produce-an-error-while-its-twin-works-fine/327456/6 "2015-08-03T06:37:43Z")

</div>

this code builds without error

MyCharacter.h

```
#include "GameFramework/Character.h"
#include "MyActorComponent.h"
#include "MyCharacter.generated.h"

UCLASS()
class LIGHTARRAY_API AMyCharacter : public ACharacter
{
	GENERATED_BODY()

public:
	// Sets default values for this character's properties
	AMyCharacter();

	// Called when the game starts or when spawned
	virtual void BeginPlay() override;
	
	// Called every frame
	virtual void Tick( float DeltaSeconds ) override;

	// Called to bind functionality to input
	virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override;

	UMyActorComponent* MyActorComponent_ref;
	
};

```

MyActorComponent.h

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

#pragma once

#include "Components/ActorComponent.h"
#include "MyActorComponent.generated.h"

UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class LIGHTARRAY_API UMyActorComponent : public UActorComponent
{
	GENERATED_BODY()

public:	
	// Sets default values for this component's properties
	UMyActorComponent();

	// Called when the game starts
	virtual void BeginPlay() override;
	
	// Called every frame
	virtual void TickComponent( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction ) override;

};

```

can you show your classes declaration?

UCombat  
UPerception

---

<div class="post-metadata">

**Author:** ![Bolt-Action\_Balrog](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Bolt-Action\_Balrog](https://forums.unrealengine.com/u/Bolt-Action_Balrog)\
**Post date:** [August 3, 2015, 6:42am UTC](https://forums.unrealengine.com/t/why-does-one-of-my-declarations-produce-an-error-while-its-twin-works-fine/327456/7 "2015-08-03T06:42:47Z")

</div>

This looks like it might be a linker error. Did you include #pragma once on top of both of your header files?

---

<div class="post-metadata">

**Author:** ![HInoue](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@HInoue](https://forums.unrealengine.com/u/HInoue)\
**Post date:** [August 3, 2015, 6:48am UTC](https://forums.unrealengine.com/t/why-does-one-of-my-declarations-produce-an-error-while-its-twin-works-fine/327456/8 "2015-08-03T06:48:57Z")

</div>

Neither class has content yet, both simply contain the call to generated\_body.

---

<div class="post-metadata">

**Author:** ![happyhorror\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@happyhorror\_1](https://forums.unrealengine.com/u/happyhorror_1)\
**Post date:** [August 3, 2015, 7:01am UTC](https://forums.unrealengine.com/t/why-does-one-of-my-declarations-produce-an-error-while-its-twin-works-fine/327456/9 "2015-08-03T07:01:44Z")

</div>

sry, but then i have no idea what cause problem in your implementation without looking into full version, as i told code i gave above builds without error, if you won’t share your code for some reason, then you can try one of these:

try recreate your classes without copying tons of lines, maybe just names, in this case you may find something different

or

try remove extra parts in your code step by step to reduce code down to raw template version and check when it builds without errors, from this point you can try find what’s wrong with last removed part

---

<div class="post-metadata">

**Author:** ![HInoue](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@HInoue](https://forums.unrealengine.com/u/HInoue)\
**Post date:** [August 3, 2015, 7:29am UTC](https://forums.unrealengine.com/t/why-does-one-of-my-declarations-produce-an-error-while-its-twin-works-fine/327456/10 "2015-08-03T07:29:58Z")

</div>

Thank you for trying to help anyway. 🙂

---

<div class="post-metadata">

**Author:** ![HInoue](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@HInoue](https://forums.unrealengine.com/u/HInoue)\
**Post date:** [August 3, 2015, 7:31am UTC](https://forums.unrealengine.com/t/why-does-one-of-my-declarations-produce-an-error-while-its-twin-works-fine/327456/11 "2015-08-03T07:31:50Z")

</div>

Darn, I was hoping that was the mistake, but the #pragma is in place- both headers read like this:

```
#pragma once

#include "Morpheme.h"
#include "MCharacter.h"
#include "Kismet/GameplayStatics.h"
#include "Perception.generated.h"

/**
 * 
 */
UCLASS()
class MONSTERSCHOOL_API UPerception : public UMorpheme
{
	GENERATED_BODY()

};
```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_71c55af3](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_71c55af3](https://forums.unrealengine.com/u/anonymous_user_71c55af3)\
**Post date:** [August 3, 2015, 8:40am UTC](https://forums.unrealengine.com/t/why-does-one-of-my-declarations-produce-an-error-while-its-twin-works-fine/327456/12 "2015-08-03T08:40:28Z")

</div>

I think _Bolt-Action Balrog_ is right. This is a linker error. If you by any chance come across:

```
// This gives errors
SomeClass Instance;

// And this doesnt give any error
class SomeClass Instance;

```

Then it means linker cant link your SomeClass because it can not find it. What you are achieving by adding class in front of it is forward declaration. So it still can not find but thinks you will create it at some point.

Check if you included the correct header for your class and be sure your class is properly created.

---

<div class="post-metadata">

**Author:** ![HInoue](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@HInoue](https://forums.unrealengine.com/u/HInoue)\
**Post date:** [August 3, 2015, 9:06am UTC](https://forums.unrealengine.com/t/why-does-one-of-my-declarations-produce-an-error-while-its-twin-works-fine/327456/13 "2015-08-03T09:06:39Z")

</div>

You’re both absolutely right, the line causing the problem was one of the includes:

```
#include "MCharacter.h"

```

MCharacter is my custom character class, I confirmed that it’s correctly spelled and that there’s no circular reference anywhere, is there any other obvious reason why this would break the linker?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_71c55af3](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_71c55af3](https://forums.unrealengine.com/u/anonymous_user_71c55af3)\
**Post date:** [August 3, 2015, 9:37am UTC](https://forums.unrealengine.com/t/why-does-one-of-my-declarations-produce-an-error-while-its-twin-works-fine/327456/14 "2015-08-03T09:37:34Z")

</div>

Can you copy-paste every error you get from the output?

---

<div class="post-metadata">

**Author:** ![HInoue](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@HInoue](https://forums.unrealengine.com/u/HInoue)\
**Post date:** [August 3, 2015, 9:52am UTC](https://forums.unrealengine.com/t/why-does-one-of-my-declarations-produce-an-error-while-its-twin-works-fine/327456/15 "2015-08-03T09:52:17Z")

</div>

Yea sure, if I re-add the #include"MCharacter.h", I get this in the log, where MCharacter.h(97) is the line where I declare a variable of type UPerception\*:

```
Info Compiling game modules for hot reload
Info Parsing headers for MonsterSchoolEditor
Info LogCompile:Error: Circular dependency detected for filename C:\Users\username\Documents\Unreal Projects\projectname\Source\projectname\MCharacter.h!
Info Reflection code generated for MonsterSchoolEditor
Info Performing 7 actions (4 in parallel)
Info Perception.cpp
Info MCharacter.cpp
Info HitframeNotifyState.cpp
Info projectname.generated.cpp
Error c:\users\username\documents\unreal projects\projectname\source\ projectname \MCharacter.h(97) : error C2143: syntax error : missing ';' before '*'
Error c:\users\ username \documents\unreal projects\ projectname \source\ projectname \MCharacter.h(97) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Info CharacterStateChangeNotify.cpp
Info TransitionZone.cpp
```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_359f4d3c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_359f4d3c](https://forums.unrealengine.com/u/anonymous_user_359f4d3c)\
**Post date:** [August 3, 2015, 9:54am UTC](https://forums.unrealengine.com/t/why-does-one-of-my-declarations-produce-an-error-while-its-twin-works-fine/327456/16 "2015-08-03T09:54:59Z")

</div>

Looks like a circular reference to me, especially if it works if you prefix the declaration with “class”.

If your MCharacter inherits from ACharacter, that means that MCharacter includes the character header (which includes Perception.h), while Perception.h also tries to include MCharacter.h.

To solve this, you need a forward declaration, which is precisely prefixing the declaration with class:

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — https://unrealcommunity.wiki/! You will be able to find content from...

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_71c55af3](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_71c55af3](https://forums.unrealengine.com/u/anonymous_user_71c55af3)\
**Post date:** [August 3, 2015, 10:05am UTC](https://forums.unrealengine.com/t/why-does-one-of-my-declarations-produce-an-error-while-its-twin-works-fine/327456/17 "2015-08-03T10:05:50Z")

</div>

Here are my assumptions:

1. You have a circular dependency like this:

My suggestions:

- Restructure your both classes
- Use forward-declaration

Both are fine but remember, circular dependency generally means, bad structered class hiearchy

1. The line before MCharacter.h(97) is missing a ‘;’ at the end.

2. At line 97 you have a type that is not declared yet, which is probably an effect of circular dependency

It could also be UnrealBuildTool detecting circular dependency and doing something on his own to solve this and causing the 3th problem.

---

<div class="post-metadata">

**Author:** ![happyhorror\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@happyhorror\_1](https://forums.unrealengine.com/u/happyhorror_1)\
**Post date:** [August 3, 2015, 10:10am UTC](https://forums.unrealengine.com/t/why-does-one-of-my-declarations-produce-an-error-while-its-twin-works-fine/327456/18 "2015-08-03T10:10:52Z")

</div>

glad to hear cut step by step work always ^^

i have an idea how it can happen:

1. #include “MCharacter.h” mean this file must be in same folder as current where it wrote, isn’t here red underline on this include in VS? if no red underline, then it just strange
2. i saw it’s possible to choose public or private when creating class in UE4 and in VS project have 2 separate folders, i think if your MCharacter.h inside “private” folder for example and another .h where you try include it from “public” folder - then VS can’t just find where the hell file is 😃 and for some reason doesn’t rise correct error
3. if you were deleting files from VS solution, note that files maybe not deleted physicly on HDD and exist in window’s file explorer, in this case you may get strange situation when you have actually 2 files MCharacter.h inside “public” and “private” folder and if your file where you include it lay in wrong folder, tricky VS can find it on HDD and think all fine, while it’s totaly wrong and you want use really another one

---

<div class="post-metadata">

**Author:** ![happyhorror\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@happyhorror\_1](https://forums.unrealengine.com/u/happyhorror_1)\
**Post date:** [August 3, 2015, 10:16am UTC](https://forums.unrealengine.com/t/why-does-one-of-my-declarations-produce-an-error-while-its-twin-works-fine/327456/19 "2015-08-03T10:16:37Z")

</div>

just a remind - don’t forget mark question as answered with little gray circle button under any answer (not comment, but whole answer) when problem solved, so anyone else later can have same question and may find solution faster, if you find solution on your own, don’t forget write it too, really interesting who’s bad guy in this problem 😛

it’s already like detective movie for me xD

---

<div class="post-metadata">

**Author:** ![HInoue](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@HInoue](https://forums.unrealengine.com/u/HInoue)\
**Post date:** [August 3, 2015, 10:29am UTC](https://forums.unrealengine.com/t/why-does-one-of-my-declarations-produce-an-error-while-its-twin-works-fine/327456/20 "2015-08-03T10:29:59Z")

</div>

Hmm okay, I’ll take a look at restructuring… thank you so much for the analysis 🙂

[Next page](https://forums.unrealengine.com/t/why-does-one-of-my-declarations-produce-an-error-while-its-twin-works-fine/327456.md?page=2)
