Compiler Error C2084 after creating Tank.cpp

Hey there,
i’m getting compile Error C2084 “Function ATank::ATank(void) already has a body” after I added Tank subclass.
I’m using Unreal 5.1.1 and this is my code:

Tank.h

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "BasePawn.h"
#include "Tank.generated.h"

/**
 * 
 */
UCLASS()
class TOONTANKS_API ATank : public ABasePawn
{
	GENERATED_BODY()

private:
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category= "Toon Tanks", meta=(AllowPrivateAccess="true"))
	class USpringArmComponent* SpringArm;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category= "Toon Tanks", meta=(AllowPrivateAccess="true"))
	class UCameraComponent* Camera;
};

Tank.cpp

// Fill out your copyright notice in the Description page of Project Settings.


#include "Tank.h"

#include "Camera/CameraComponent.h"
#include "GameFramework/SpringArmComponent.h"


ATank::ATank()
{
	SpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("Spring Arm"));
	SpringArm->SetupAttachment(RootComponent);

	Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));
	Camera->SetupAttachment(SpringArm);
}

Thanks for your help!

1 Like

Kinda hard to tell without seeing the full class (unless that’s it).

But it’s complaining that ATank::ATank() (classes constructor) has already been defined somewhere. Double check that somewhere in your code that ATank::ATank() isn’t being defined twice. You may have Another Tank class derived from ATank or something.

You haven’t declared the constructor in your class.

class TOONTANKS_API ATank : public ABasePawn
{
	GENERATED_BODY()
public:
    ATank(); // missing
private:
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category= "Toon Tanks", meta=(AllowPrivateAccess="true"))
	class USpringArmComponent* SpringArm;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category= "Toon Tanks", meta=(AllowPrivateAccess="true"))
	class UCameraComponent* Camera;
};

Bit of a confusing error message but it is presumably talking about the one the compiler will generate for you if you don’t declare one yourself.

ah ! Nice! Yes that was it ! Thanks for the fast help!
Indeed a misleading error message

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms