Custom header file

Greetings,

i wan to to create a custom header and there have some util functions. Thus, i made this function:

    #ifndef A_UTIL_H
    #define A_UTIL_H
    
    void PrintLog(FString txt){
       UE_LOG(LogTemp,Warning,TEXT("%s"), *txt);
    }
    
    #endif

I include this header to a .cpp file of an ue4 actor and everything is fine. On a second file , when i try to include the header it says that i have multiple definitions… The a_util.h is stored in my porjects → Source ->projname file.

Thanks in advance.

#pragma once instead of header guard?

nop… nothing… How do you write a custom header so that you can use in every c++ file? is it not a header file?

Show us the error stack.

Either use inline or separate the declaration from the implementation (.h, .cpp).

Hey, it just says multiple definitions for my two functions

can you show code or be more specific please? :slight_smile:

If inline then in the header file:

     inline void PrintLog(FString txt){
        UE_LOG(LogTemp,Warning,TEXT("%s"), *txt);
     }

If inline doesn’t work, then try separating the declaration from its implementation:

in header file (.h):

 void PrintLog(FString);

in source file (.cpp):

     void PrintLog(FString txt){
        UE_LOG(LogTemp,Warning,TEXT("%s"), *txt);
     }

Hey, with the inline it stops the error builds. I made a function that searches for an asset called FindAsset. When i give the path of the asset for both of my things, then, it is completely wrong. for some reason it takes the asset of another file instead of its own cpp file…

I don’t understand what the problem is.

no worries my friend, i fixed it! I made a header and a cpp file and now its all good!!! Thanks so much!