LightSwitch example not working

New to c++, totally lost on this example which is supposed to show how to bring c++ stuff into blueprints, I’ve attached the code, the example is taken from here: CPP and Blueprints Example | Unreal Engine 5.1 Documentation

It gives an error at the bolded part below:

  • no instance of overloaded function matches “ALightSwitchBoth::CreateDefaultSubobject” matches the argument list

argument types are: (ALightSwitchBoth*, const wchar_t[8])

LightSwitchBoth.cpp

#include “GameProject7.h”
#include “LightSwitchBoth.h”

ALightSwitchBoth::ALightSwitchBoth()
{

DesiredIntensity = 3000.0f;

PointLight1 = CreateDefaultSubobject<UPointLightComponent>(TEXT("PointLight1"));
PointLight1->Intensity = DesiredIntensity;
PointLight1->bVisible = true;
RootComponent = PointLight1;

Sphere1 = **CreateDefaultSubobject**<USphereComponent>(this, TEXT("Sphere1"));
Sphere1->InitSphereRadius(250.0f);
Sphere1->AttachParent = RootComponent;

Sphere1->OnComponentBeginOverlap.AddDynamic(this, &ALightSwitchBoth::OnOverlapBegin);       // set up a notification for when this component overlaps something
Sphere1->OnComponentEndOverlap.AddDynamic(this, &ALightSwitchBoth::OnOverlapEnd);       // set up a notification for when this component overlaps something

}

void ALightSwitchBoth::OnOverlapBegin_Implementation(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
if (OtherActor && (OtherActor != this) && OtherComp)
{
ToggleLight();
}
}

void ALightSwitchBoth::OnOverlapEnd_Implementation(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
if (OtherActor && (OtherActor != this) && OtherComp)
{
ToggleLight();
}
}

void ALightSwitchBoth::ToggleLight()
{
PointLight1->ToggleVisibility();
}

LightSwitchBoth.h

#include “GameFramework/Actor.h”
#include “LightSwitchBoth.generated.h”

UCLASS()
class GAMEPROJECT7_API ALightSwitchBoth : public AActor
{
GENERATED_BODY()
public:
/** point light component /
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = “Switch Components”)
class UPointLightComponent
PointLight1;

/** sphere component */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Switch Components")
class USphereComponent* Sphere1;

ALightSwitchBoth();

/** called when something enters the sphere component */
UFUNCTION(BlueprintNativeEvent, Category = "Switch Functions")
	void OnOverlapBegin(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);

void OnOverlapBegin_Implementation(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);

/** called when something leaves the sphere component */
UFUNCTION(BlueprintNativeEvent, Category = "Switch Functions")
	void OnOverlapEnd(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);

void OnOverlapEnd_Implementation(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);

/** Toggles the light component's visibility*/
UFUNCTION()
	void ToggleLight();

/** the desired intensity for the light */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Switch Variables")
	float DesiredIntensity;

};

i was having the same issue and i posted a thread, here is the link if you need reference How can i create OnComponentBeginOverlap Event using c++ - C++ - Epic Developer Community Forums

try changing this
Sphere1->OnComponentBeginOverlap.AddDynamic(this, &ALightSwitchBoth::OnOverlapBegin); // set up a notification for when this component overlaps something
Sphere1->OnComponentEndOverlap.AddDynamic(this, &ALightSwitchBoth::OnOverlapEnd); // set up a notification for when this component overlaps something

for this
Sphere1->OnComponentBeginOverlap.AddDynamic(this, &ALightSwitchBoth::OnOverlapEnd_Implementation); // set up a notification for when this component overlaps something
Sphere1->OnComponentEndOverlap.AddDynamic(this, &ALightSwitchBoth::OnOverlapEnd_Implementation); // set up a notification for when this component overlaps something