Forward Declaration Error

When I forward declare my “APlayerCharacter” class in .h files and include it in .cpp this error shows up:

0>UE_4.26\Engine\Source\Runtime\CoreUObject\Public\Templates/SubclassOf.h(64): Error C2027 : use of undefined type 'APlayerCharacterBase'
0>{ProjectDir}/Player/Others/DataAssets/DataAsset_Player.h(10): Reference C2027 : see declaration of 'APlayerCharacterBase'
0>UE_4.26\Engine\Source\Runtime\CoreUObject\Public\Templates/SubclassOf.h(63): Reference C2027 : while compiling class template member function 'UClass *TSubclassOf<APlayerCharacterBase>::operator *(void) const'
0>UE_4.26\Engine\Source\Runtime\CoreUObject\Public\Templates/SubclassOf.h(86): Reference C2027 : see reference to function template instantiation 'UClass *TSubclassOf<APlayerCharacterBase>::operator *(void) const' being compiled
0>{ProjectDir}/Player/Others/DataAssets/DataAsset_Characters.h(20): Reference C2027 : see reference to class template instantiation 'TSubclassOf<APlayerCharacterBase>' being compiled
0>UE_4.26\Engine\Source\Runtime\CoreUObject\Public\Templates/SubclassOf.h(64): Error C2672 : 'StaticClass': no matching overloaded function found
0>UE_4.26\Engine\Source\Runtime\CoreUObject\Public\Templates/SubclassOf.h(64): Error C2783 : 'UClass *StaticClass(void)': could not deduce template argument for 'ClassType'
0>UE_4.26\Engine\Source\Runtime\CoreUObject\Public\UObject/ReflectedTypeAccessors.h(13): Reference C2783 : see declaration of 'StaticClass'




It was all working fine a few compiles earlier.


Its solved by removing the forward declare and including the header directly.


But I was wondering why is this happening?

Can you show the header how you use the forward declared class?
There’s certainly limits to what you can do with the type. You can’t use it as a baseclass for example. You can have a pointer to it (most common usage for forward declared types).
I’m just guessing here, but maybe you’re using it for something that needs the memory layout of the class.
Check this:
https://stackoverflow.com/a/553869

I am just using my forward declaration for pointers only. But its this single class that is causing the issue. (Its an abstract uclass)