Create widget in c++

How to create a c++ widget without blueprint child class?
I found these solutions but they don’t work, i guess they’re too old:
https://gist.github.com/SalahAdDin/b3814f109d340f1e0f5dcac6e623b8ce
For this one seems like setting RootWidget doesn’t do anything because in widget reflector it appears same as if NativeConstruct would be empty-There is SObjectWidget with SSpacer inside

	Super::NativeConstruct();
	UPanelWidget* rootWidget = Cast<UPanelWidget>(GetRootWidget());
	auto button = WidgetTree->ConstructWidget<UButton>(UButton::StaticClass());
	rootWidget->AddChild(button);

Also this one doesn’t work-GetRootWidget() returns null

Hey @Kryst-ian, welcome to the forums!
The only issue I can see is your auto typing - it itself is not a type, but a placeholder for one. I cannot be used in certain casts or operators, so my only recommendation is to possibly have your button typed as a UButton. You may have this already since I can’t see your header file, but this is the only problem I can see within your code.
I also found a question from a while back whose answer might show you something to spark your thoughts: Create widget in pure C++ - #2 by Shohei
I hope this can help!
-Zen