AddViewportWidgetContent(SNew gives error "'MakeTDecl': no matching overloaded function found"

I have minimal test project for a menu from the forum where the new class SMainMenu is derived from SCompoundWidget.

This is the header of the class:

#pragma once

#include "Slate.h"

class SMainMenu : public SCompoundWidget
{
public:
	SLATE_BEGIN_ARGS(SMainMenu)
	{}
	SLATE_END_ARGS()

	// Constructor for slate widgets
	void Construct(const  FArguments& InArgs);

private:

	//Start  button callback 
	FReply StartBtnClicked();

   [...]

	//Function to Create Menu 
	TSharedRef<SWidget> MyMenu();
};

My HUD class has a member variable MyUIWidget.
In my HUD cpp I use it like this:

MyUIWidget = SNew(SMainMenu); 
GEngine->GameViewport->AddViewportWidgetContent(SNew(MyUIWidget.ToSharedRef() ) );
MyUIWidget->SetVisibility(EVisibility::Visible);

This gives me the error:

error C2672: 'MakeTDecl': no matching overloaded function found
error C2974: 'MakeTDecl': invalid template argument for 'WidgetType', type expected

If I use instead

GEngine->GameViewport->AddViewportWidgetContent(MyUIWidget.ToSharedRef());

It seems to work. I get a GUI. Not really tested for further problems.

Now my questions:

  1. Is the second version without error the correct version and the API documentation is wrong? (I don’t think so, to be honest)

  2. If the first version - the one with the error - is the correct one, what is the meaning of that error? How do I fix this? And why?

I found my answer in the “Strategy Game”, the sample project we get for free.

GEngine->GameViewport->AddViewportWidgetContent(SNew(SWeakWidget).PossiblyNullContent(MyUIWidget.ToSharedRef() ) );