Sure that’s fine. In a header which you include in multiple cpp files:
// Declare the constant string:
extern const FString SomeString;
In a single cpp file:
#include "SomeString.h"
// Define the constant string:
const FString SomeString = "Something";
In any cpp file:
#include "SomeString.h"
// Use the constant string:
void Test(const TMap<FString, UObject*>& Map){
UObject* obj = Map[SomeString];
}
Some other tips:
- Pass
TMap
(and other containers likeTArray
) by reference, likeconst TMap<...> & Param
orTMap<...> & Param
if you want to modify it. Otherwise you’re copying the container every time you pass it as an argument to a function. - Use
FName
rather thanFString
for these. It’s much faster to compare names than strings and they’re a natural fit forTMap
keys for this reason.