unresolved external symbol TSizedAllocatorBase<>::ForAnyElementType::ForAnyElementType(class ... const &)

The problem is simple. In a recent commit for TArray, a copy constructor got added in the new `ForAnyElementType` type, and this copy constructor is not defined. Meaning anything using it will break.

The problem is the emission of TArray<T>::PadToNum and other items that will force usage of the new undefined copy constructor.

The fix is : Do not have a pattern where you do a class MYMODULE_API FMyClass : public TArray<Something>, or else, it will force the definition of TArray<T>::PadToNum and other elements requiring the copy constructor, and it will add a linking error.

I am providing this here mostly for visibility, as it’s REALLY HARD to figure out that issue with nondescript linking errors pointing to the same, with no guidance from “used in …” (thanks, Visual Studio Linker).

If you ever need to figure it out in a huge module, a trick is to use the dreaded bPreprocessOnly = true; in your Target, compile one of your linked error file (ONLY ONE FILE!), remove the target flag (because lord forbid you compile an entire project with this), and then use the generated intermediate .i file to search for TArray, and figure out what you might be doing wrong in your code. Good luck, you’ll need it!

Steps to Reproduce
Create an exported class that’s derived from a TArray.

You will get linking errors such as this one:

unresolved external symbol "protected: __cdecl TSizedAllocatorBase<32,class TSizedHeapAllocator<32,struct FMemory>>::ForAnyElementType::ForAnyElementType(class ... const &)"



Hi, I tried what you suggested and didn’t get any linkage error. I’m pretty sure that no function - and particularly PadToNum - should be attempting to call those copy constructors and assignment operators.

That said, they are a remnant from pre-C++11 and are better written these days as public and as TSizedAllocatorBase(const TSizedAllocatorBase&) = delete;. Can you try that and let me know if it works for you? This should stop the compiler attempting to link to those functions entirely. I will make the equivalent change here, because that’s the preferable and more modern approach anyway.

Steve

The deletion of those copy functions in allocators was submitted and is visible here:

https://github.com/EpicGames/UnrealEngine/commit/e3bd4b59e7c97ff26f2d7ba58053b09498be15e4

Steve

It worked! :slight_smile: Thank you!

Great, thanks for the confirmation!

Steve