how to make a class look like a built-in data type for function returns

I've noticed that a function with a return type of String will also allow returns of const char * as the following code demonstrates:

void setup() {
Serial.begin(250000);
Serial.println(testFunc(true));
Serial.println(testFunc(false));
}

String testFunc(bool retStringType)
{
  if(retStringType == true)
    {
    String s = "String object return type";
    return s;
    }
  else
    return("const char * return type");
}

void loop() {
}

It throws no errors or warnings during compilation and works fine. The output when run is:

String object return type
const char * return type

What is the requirement/technique which allows the String class to do this?

I've been trying to search google to figure this out but I can't even figure out what to call this property of a class.

Overload constructor of your class so the compiler knows how to construct your object from those arguments.

Thank you!

roger68k:
I've noticed that a function with a return type of String will also allow returns of const char * as the following code demonstrates:

No, your testFunc() ONLY returns a String. The return statement:

return("const char * return type");

Creates a new String object using the provided string literal. That new String object is what the function returns.

As @arduino_new mentioned, the String class is able to do this because it has an overloaded constructor that accepts a string literal for its argument.

Thanks gfvalvo!

That concisely clears up my confusion.