I use RegisterStringFactory to register my own string type, basically something similar to std::string_view.
So AS will see them as “const string_view” after creation.
The type is registerd with asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<T>().
Now usually I pass my strings to functions by copy.
RegisterObjectMethod("obj", "void SetName(string_view)", asMETHOD(obj, SetName, asCALL_THISCALL);
->
obj.SetName("Jonny"); // works fine
So even though the string constant “Jonny” is treated as “const string_view”, this works.
EXCEPT in constrctors.
RegisterObjectBehaviour("obj", asBEHAVE_CONSTRUCT, "void f(string_view)", asFUNCTION(obj_ConstructView), asCALL_CDECL_OBJFIRST);
obj b("Jonny"); // DESON'T work
I get the error message, that there is no overload that takes “const string_view”. So if I change the behavior to this declaration, I get it to work:
RegisterObjectBehaviour("obj", asBEHAVE_CONSTRUCT, "void f(const string_view)", asFUNCTION(obj_ConstructView), asCALL_CDECL_OBJFIRST);
I really just add the “const” in the declaration.
Could this be an oversight? As far as I understand it, the constructor should also work without the const, since string_view should just be copied anyway.