(UE4-23) We have in Archive.h
class CORE_API FArchive
{
public:
virtual FArchive& operator<<(FName& Value)
{
return *this;
}
Normally it’s overrided in somewhere like LinkerLoad.h, which is for package.
Now I’m doing something generic outside of LinkerLoad, and I’m trying to use
FArchiveFileReaderGeneric and FArchiveFileWriterGeneric and it’s ok for TArray/TMap.
Since I need an operator<< override for FName, when I added this in FArchiveFileReaderGeneric:
class CORE_API FArchiveFileReaderGeneric : public FArchive
{
public:
...
virtual FArchive& operator<<(FName& Value) final
{
FNameEntryId comparisonIndex;
FNameEntryId displayIndex;
uint32 number;
*this << comparisonIndex;
*this << displayIndex;
*this << number;
Value = FName(comparisonIndex, displayIndex, number);
return *this;
}
And turned out, it can’t resolve to the derived<< with the following
FArchive* ia = IFileManager::Get().CreateFileReader(*archiveFile);
FName test;
(*ia).operator<<(test); //base<<
(*ia) << test; //base<<
So I changed it to
FArchiveFileReaderGeneric& ia = *static_cast<FArchiveFileReaderGeneric*>(IFileManager::Get().CreateFileReader(*archiveFile));
FName test;
ia.operator<<(test); //derived<<, but only with 'final', not 'override'
ia << test; //base<<
Finally my question is, how should I design it so
that ia << test; will go to the derived << implementation? Thanks.