How to create/add bp extended component in C++

Hi,

I have created a custom bp component based on UWidgetComponent. And I want to create/add this bp component in my actor’s constructor. I tried the following code but it doesn’t work:

ConstructorHelpers::FClassFinder<UWidgetComponent> DisplayWidgetTest(TEXT("/Game/Test/BP/NameWidgetBP"));

DisplayNameTest = CreateDefaultSubobject<DisplayWidgetTest.Class>(TEXT("Test"));

The compiler says the argument type is not matching, could you tell me what is the correct method to achieve my intention?

Thanks!

For Anyone who need this:

DisplayNameTest = static_cast<UWidgetComponent*>(CreateDefaultSubobject(TEXT("TestWidget"), UWidgetComponent::StaticClass(), *DisplayNameWidgetTest.Class, true, false));

This will give the owner a bp extended UWidgetComponent attached.