member function already defined or declared, but how ?

Hello,

I trying to overload operator=, but I got an error every time I tried

This is the .h

#pragma once

#include “CoreMinimal.h”
#include
#include
#include “Kismet/BlueprintFunctionLibrary.h”
#include “LargeNumber.generated.h”

using namespace std;

UCLASS()
class IDLECLICKER_API ULargeNumber : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
private:
string digits;
public:
ULargeNumber();
ULargeNumber& operator=(const ULargeNumber&);
};

this is the cpp

#include “LargeNumber.h”

ULargeNumber& ULargeNumber::operator=(const ULargeNumber& a)
{
digits = a.digits;
return *this;
}

ULargeNumber::ULargeNumber()
{
digits = “”;
digits.push_back(‘0’);
}

And this is the error

1>[1/6] Compile LargeNumber.cpp
1>LargeNumber.h(21): error C2535: ‘ULargeNumber &ULargeNumber::operator =(const ULargeNumber &)’: member function already defined or declared
1>LargeNumber.h(16): note: see declaration of ‘ULargeNumber::operator =’
1>[2/6] Compile LargeNumber.gen.cpp
1>LargeNumber.h(21): error C2535: ‘ULargeNumber &ULargeNumber::operator =(const ULargeNumber &)’: member function already defined or declared
1>LargeNumber.h(16): note: see declaration of ‘ULargeNumber::operator =’

I tried like the 3 first page of google search about this error on this operator but nothing worked, does anyone has an idea ? is this a new bug in 5.1 ?
Thanks

You need to use the FORCEINLINE macro for operator overloads.

You are programming inside the Unreal Engine framework, don’t use stuff like the standard library and apart from basic types like int and float, use the Unreal Engine equivalents such as FString instead of string. The class you’re deriving from is a bit suspect too, it’s meant for static C++ functions callable as nodes in blueprints.

You mean, byt changing
ULargeNumber& operator=(const ULargeNumber&);
to
FORCEINLINE ULargeNumber& operator=(const ULargeNumber&);
in the header ?

That doesn’t work either, i’ve already tried this solution before

From BlueprintFunctionLibrary.h

// This class is a base class for any function libraries exposed to blueprints.
// Methods in subclasses are expected to be static, and no methods should be added to this base class.

oh … okay thanks, i’ll continue searching to see where to put this code

I got it by doing a USTRUCT(BlueprintType), thanks for the help guys