Extend UButton in c++

I want to extend UButton class but the compiler gives failure.

#pragma once

#include "Components/Button.h"
#include "BtnSlot.generated.h"

UCLASS()
class TOWERDEFENCE_API UBtnSlot : public UButton
{
	GENERATED_BODY()
	
};

Severity Code Description Project File Line
Error MSB3073 The command ““C:\Program Files\Epic Games\4.10\Engine\Build\BatchFiles\Build.bat” TowerDefenceEditor Win64 Development “D:\ProjetosUE4\ProjetoX\projetox\TowerDefence\TowerDefence.uproject” -rocket -waitmutex” exited with code -1. TowerDefence C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.MakeFile.Targets 37
Error C2504 ‘UContentWidget’: base class undefined TowerDefence C:\Program Files\Epic Games\4.10\Engine\Source\Runtime\UMG\Public\Components\Button.h 23
Error C2504 ‘UContentWidget’: base class undefinedC:\Program Files\Epic Games\4.10\Engine\Source\Runtime\UMG\Public\Components/Button.h(24): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int TowerDefence C:\Program Files\Epic Games\4.10\Engine\Source\Runtime\UMG\Public\Components\Button.h 23
Error C3646 ‘Super’: unknown override specifier TowerDefence C:\Program Files\Epic Games\4.10\Engine\Source\Runtime\UMG\Public\Components\Button.h 24
Error C3646 ‘Super’: unknown override specifier TowerDefence C:\Program Files\Epic Games\4.10\Engine\Source\Runtime\UMG\Public\Components\Button.h 24
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int TowerDefence C:\Program Files\Epic Games\4.10\Engine\Source\Runtime\UMG\Public\Components\Button.h 24
Error C3668 ‘UButton::_getUObject’: method with override specifier ‘override’ did not override any base class methods TowerDefence C:\Program Files\Epic Games\4.10\Engine\Source\Runtime\UMG\Public\Components\Button.h 24
Error C3668 ‘UButton::_getUObject’: method with override specifier ‘override’ did not override any base class methods TowerDefence C:\Program Files\Epic Games\4.10\Engine\Source\Runtime\UMG\Public\Components\Button.h 24
Error C2440 ‘return’: cannot convert from ‘UButton *’ to ‘UObject *’ TowerDefence C:\Program Files\Epic Games\4.10\Engine\Source\Runtime\UMG\Public\Components\Button.h 24
Error C2440 ‘return’: cannot convert from ‘UButton *’ to ‘UObject *’ TowerDefence C:\Program Files\Epic Games\4.10\Engine\Source\Runtime\UMG\Public\Components\Button.h 24
Error C3668 ‘UButton::SynchronizeProperties’: method with override specifier ‘override’ did not override any base class methods TowerDefence C:\Program Files\Epic Games\4.10\Engine\Source\Runtime\UMG\Public\Components\Button.h 90
Error C3668 ‘UButton::SynchronizeProperties’: method with override specifier ‘override’ did not override any base class methods TowerDefence C:\Program Files\Epic Games\4.10\Engine\Source\Runtime\UMG\Public\Components\Button.h 90
Error C3668 ‘UButton::ReleaseSlateResources’: method with override specifier ‘override’ did not override any base class methods TowerDefence C:\Program Files\Epic Games\4.10\Engine\Source\Runtime\UMG\Public\Components\Button.h 94
Error C3668 ‘UButton::ReleaseSlateResources’: method with override specifier ‘override’ did not override any base class methods TowerDefence C:\Program Files\Epic Games\4.10\Engine\Source\Runtime\UMG\Public\Components\Button.h 94
Error C3668 ‘UButton::PostLoad’: method with override specifier ‘override’ did not override any base class methods TowerDefence C:\Program Files\Epic Games\4.10\Engine\Source\Runtime\UMG\Public\Components\Button.h 98
Error C3668 ‘UButton::GetEditorIcon’: method with override specifier ‘override’ did not override any base class methods TowerDefence C:\Program Files\Epic Games\4.10\Engine\Source\Runtime\UMG\Public\Components\Button.h 102
Error C3668 ‘UButton::GetPaletteCategory’: method with override specifier ‘override’ did not override any base class methodsC:\Program Files\Epic Games\4.10\Engine\Source\Runtime\UMG\Public\Components/Button.h(98): error C3668: ‘UButton::PostLoad’: method with override specifier ‘override’ did not override any base class methods TowerDefence C:\Program Files\Epic Games\4.10\Engine\Source\Runtime\UMG\Public\Components\Button.h 103
Error C3668 ‘UButton::GetPaletteCategory’: method with override specifier ‘override’ did not override any base class methodsC:\Program Files\Epic Games\4.10\Engine\Source\Runtime\UMG\Public\Components/Button.h(110): error C3668: ‘UButton::OnSlotAdded’: method with override specifier ‘override’ did not override any base class methods TowerDefence C:\Program Files\Epic Games\4.10\Engine\Source\Runtime\UMG\Public\Components\Button.h 103
Error C3668 ‘UButton::GetSlotClass’: method with override specifier ‘override’ did not override any base class methodsC:\Program Files\Epic Games\4.10\Engine\Source\Runtime\UMG\Public\Components/Button.h(102): error C3668: ‘UButton::GetEditorIcon’: method with override specifier ‘override’ did not override any base class methods TowerDefence C:\Program Files\Epic Games\4.10\Engine\Source\Runtime\UMG\Public\Components\Button.h 109
Error C3668 ‘UButton::GetSlotClass’: method with override specifier ‘override’ did not override any base class methods TowerDefence C:\Program Files\Epic Games\4.10\Engine\Source\Runtime\UMG\Public\Components\Button.h 109
Error C2061 syntax error: identifier ‘UPanelSlot’ TowerDefence C:\Program Files\Epic Games\4.10\Engine\Source\Runtime\UMG\Public\Components\Button.h 110
Error C2061 syntax error: identifier ‘UPanelSlot’ TowerDefence C:\Program Files\Epic Games\4.10\Engine\Source\Runtime\UMG\Public\Components\Button.h 110
Error C3668 ‘UButton::OnSlotAdded’: method with override specifier ‘override’ did not override any base class methods TowerDefence C:\Program Files\Epic Games\4.10\Engine\Source\Runtime\UMG\Public\Components\Button.h 110
Error C2061 syntax error: identifier ‘UPanelSlot’ TowerDefence C:\Program Files\Epic Games\4.10\Engine\Source\Runtime\UMG\Public\Components\Button.h 111
Error C2061 syntax error: identifier ‘UPanelSlot’ TowerDefence C:\Program Files\Epic Games\4.10\Engine\Source\Runtime\UMG\Public\Components\Button.h 111
Error C3668 ‘UButton::OnSlotRemoved’: method with override specifier ‘override’ did not override any base class methods TowerDefence C:\Program Files\Epic Games\4.10\Engine\Source\Runtime\UMG\Public\Components\Button.h 111
Error C3668 ‘UButton::OnSlotRemoved’: method with override specifier ‘override’ did not override any base class methods TowerDefence C:\Program Files\Epic Games\4.10\Engine\Source\Runtime\UMG\Public\Components\Button.h 111
Error C3668 ‘UButton::RebuildWidget’: method with override specifier ‘override’ did not override any base class methods TowerDefence C:\Program Files\Epic Games\4.10\Engine\Source\Runtime\UMG\Public\Components\Button.h 122
Error C3668 ‘UButton::RebuildWidget’: method with override specifier ‘override’ did not override any base class methods TowerDefence C:\Program Files\Epic Games\4.10\Engine\Source\Runtime\UMG\Public\Components\Button.h 122
Error Failed to produce item: D:\ProjetosUE4\ProjetoX\projetox\TowerDefence\Binaries\Win64\UE4Editor-TowerDefence-3138.dll TowerDefence D:\ProjetosUE4\ProjetoX\projetox\TowerDefence\Intermediate\ProjectFiles\ERROR 1
Error (active) this declaration has no storage class or type specifier TowerDefence d:\ProjetosUE4\ProjetoX\projetox\TowerDefence\Source\TowerDefence\BtnSlot.h 11
Error (active) expected a ‘;’ TowerDefence d:\ProjetosUE4\ProjetoX\projetox\TowerDefence\Source\TowerDefence\BtnSlot.h 12
Error C2440 ‘return’: cannot convert from ‘UBtnSlot *’ to ‘UObject *’ TowerDefence d:\projetosue4\projetox\projetox\towerdefence\source\towerdefence\BtnSlot.h 20
Error C2440 ‘return’: cannot convert from ‘UBtnSlot *’ to ‘UObject *’ TowerDefence D:\ProjetosUE4\ProjetoX\projetox\TowerDefence\Source\TowerDefence\BtnSlot.h 20

I tryed this solution and don’t work for me.

Before you #include Button.h ,you need to #include ContentWidget.h

121670-ff.png

Hi Edney,

There are a couple things that you need to do to get this to work. First, make sure you have added the Slate, SlateCore, and UMG modules to the Public Dependency Module Names in your project’s Build.cs file. Second, open your project’s header file and add a #include "UMG.h" line.

Once you have done that, your project should build fine.