Abstract Method

Guys I wanted to create an abstract method; however, compiler gives me error. Is it not possible to create one or there is another way rather than the pure c++ coding(e.g. UFUNCTION(bla bla))?

Abstract Class:

class THECLOUDGAME_API AGround : public AMovingPawn
	virtual TArray<AGround*> GetFollowingGrounds(void) = 0;


1>C:\Users\ErayT\UnrealEngine\UnrealEngine_4.3\Engine\Source\Runtime\CoreUObject\Public\UObject\Class.h(2151): error C2259: 'AGround' : cannot instantiate abstract class
1>          due to following members:
1>          'TArray<AGround *,FDefaultAllocator> AGround::GetFollowingGrounds(void)' : is abstract
1>          C:\Users\ErayT\Documents\Unreal Projects\TheCloudGame\Source\TheCloudGame\Elements/Grounds/Ground.h(23) : see declaration of 'AGround::GetFollowingGrounds'
1>          C:\Users\ErayT\UnrealEngine\UnrealEngine_4.3\Engine\Source\Runtime\CoreUObject\Public\UObject\Class.h(2189) : see reference to function template instantiation 'void InternalConstructor<TClass>(const FPostConstructInitializeProperties &)' being compiled
1>          with
1>          [
1>              TClass=AGround
1>          ]
1>          C:\Users\ErayT\Documents\Unreal Projects\TheCloudGame\Intermediate\Build\Win64\Inc\TheCloudGame\TheCloudGame.generated.cpp(30) : see reference to function template instantiation 'void GetPrivateStaticClassBody<AGround>(const TCHAR *,const TCHAR *,UClass *&,void (__cdecl *)(void))' being compiled

You can’t use the C++ syntax for this because the Class Default Object gets instantiated. We usually use:

virtual void MyFunc() { check(0 && "You must override this"); }

Compile time would be better but this works too

1 Like

Can you help me about the returning value?

In my example a TArray must be returned. Is there a trick not to return or how can I return a null value?

Sorry, I missed that.

virtual TArray<AGround*> MyFunc() { check(0 && "You must override this"); return TArray<AGround *>(); }
1 Like

Another way:

virtual TArray<int32> MyFunc()
	return TArray<int32>();

But no compile time support too.

1 Like