I’m hoping this is a tremendously obvious syntax burp on my part, but I’m setting up events in my HUD cpp so that I can hook functionality into those functions in blueprint. One of them simply needs to fire whenever an item is picked up, and provide the name of the item to my HUD so it can display a popup for the player:
This consistently produces an error, “error C2511: ‘void AHUDManager::ItemPickupNotification(const FString &)’: overloaded member function not found in ‘AHUDManager’”.
This sounds to me like there’s another function sharing this one’s name that the compiler thinks I’m trying to override, but I have verified that no function with the same name exists within the HUD class’s scope. Moreover, removing the argument and writing it like this allows it to compile perfectly:
So is there an obvious problem here? I’ve verified that changing the function’s name but leaving the FString argument produces the same error, so it can’t be a scope conflict, but I can’t figure out another reason why it would refuse to compile.
And try if that works? Using a const-ref in this case is a typical C++ solution.
Yes, we have C++11 now and move semantics but with strings (especially std::string in other projects) it’s still probably better to just pass it by const-reference.
On a sidenote - if my theory is correct, I think this could be treated like a bug in UHT.
You’re absolutely right, this does resolve it… I wasn’t aware that passing strings by const-reference was a good idea in this context, but it definitely works; thank you!