CreateDefaultSubobject FName argument curiosity

How come the FName argument to CreateDefaultSubobject can accept a direct TEXT(“”) without having to wrap it in an FName() constructor? What is the C++ mechanism by which automatic conversion to an FName happens?

Hi,
This is standard c++ stuff.

The constructor is called implicitly with a TEXT("") argument. You can have a look at NameTypes.h in the Engine and see the implementation of FName.

these two constructors:

FName( const WIDECHAR*  Name, EFindName FindType=FNAME_Add, bool bUnused=true );
FName( const ANSICHAR* Name, EFindName FindType=FNAME_Add, bool bUnused=true );

Can be implicitly called (think about std::String, it can also be implicitly called passing a char* argument).

So, if the compiler type checking expects a FName and can call a implicit constructor it will do so.

In addition, you can forbid implicit constructor calling by flagging the constructor with “explicit” keyword, then you will have to call explictly the constructor.

Of course! I don’t know why it seemed so mysterious to me. Thanks for clearing it up.