x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Working with interfaces, multiple definition error

Hi! I'm new to UE4 interfaces and trying to implement a class that inherits from two interfaces. I'm posting the simplified code for which I'm getting Error: NoiseBase.gen.cpp.obj : error LNK2005: "public: int __cdecl INoiseBase::GetNoise(float,float,float,float,int) " (?GetNoise@INoiseBase@@QEBAHMMMMH@Z) already defined in NoiseBase.cpp.obj

This is the first interface and its NoisePattern.h

  #pragma once
     
     #include "CoreMinimal.h"
     #include "UObject/Interface.h"
     #include "NoisePattern.generated.h"
     
     class UStats;

     UINTERFACE(BlueprintType)
     class PROCEDURALWORLD_API UNoisePattern: public UInterface
     {
         GENERATED_BODY()
     };
     
     class PROCEDURALWORLD_API INoisePattern
     {
         GENERATED_BODY()
     
     public:
         UFUNCTION(BlueprintNativeEvent, BlueprintCallable)
         int Calculate(UStats* stats, FVector position);
     };

The NoisePattern.cpp file is empty it only has #include "NoisePattern.h". My second interface class NoiseBase.h:

 #pragma once
 
 #include "CoreMinimal.h"
 #include "UObject/Interface.h"
 #include "NoiseBase.generated.h"
 
 UINTERFACE(BlueprintType)
 class PROCEDURALWORLD_API UNoiseBase : public UInterface
 {
     GENERATED_BODY()
 };
 
 class PROCEDURALWORLD_API INoiseBase
 {
     GENERATED_BODY()
 
 public:
     UFUNCTION(BlueprintNativeEvent, BlueprintCallable)
     int GetNoise(float x, float y, float z, float scale, int32 max);
 };

Now I wanted to implement the GetNoise default implementation, so this is NoiseBase.cpp:

 #include "NoiseBase.h"
 #include "SimplexNoise.h"
 
 int INoiseBase::GetNoise(float x, float y, float z, float scale, int32 max)
 {
     return FMath::FloorToInt((SimplexNoise::noise(x * scale, y * scale, z * scale) + 1) * (max / 2.0f));
 }

And finally the class that inherits both of the interfaces Frequency.h:

 #pragma once
 
 #include "CoreMinimal.h"
 #include "UObject/Object.h"
 #include "NoisePattern.h"
 #include "NoiseBase.h"
 
 class UStats;
 
 class PROCEDURALWORLD_API Frequency: public INoisePattern, public INoiseBase
 {
 public:
     UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
     int Calculate(Stats* stats, FVector position);
     virtual int Calculate_Implementation(Stats* stats, FVector position) override;
 };

Frequency.cpp:

 #include "Frequency.h"
 #include "Stats.h"
 
 int Frequency::Calculate_Implementation(Stats* stats, FVector position)
 {
     return GetNoise(noisePosition.X / 100, noisePosition.Y / 100, 0, stats->frequency, stats->elevation);
 }

The NoisePattern functions normally and it successfully overrides it. The problem is this GetNoise function inside the Calculate_Implementation for which it says it has multiple definitions. Is it impossible to define the function inside the interface .cpp file?

Product Version: UE 4.19
Tags:
more ▼

asked Jan 27 '19 at 10:25 PM in C++ Programming

avatar image

BlackFlicka
3 2

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question