0

I have the following method which compiles fine using the "classic" bcc32 compiler, but fails to compile using the Rad Studio 10 Clang compiler.

TPersistentClass & __fastcall TService_REST_Server_Ol::OnServerMethods()
{
    return __classid(TServerMethods_RSO);
}

The compiler produces the following error:

[CLANG Error] Service_REST_Server_OlU.cpp(37): binding of reference to type 'TPersistentClass' (aka 'System::TMetaClass *') to a value of type 'const TClass' (aka 'System::TMetaClass *const') drops qualifiers

If I understand correctly, based on this question, the reason this does not work is because the code is attempting to return a non-const reference to a const object. However, I am unsure syntactically how I go about solving this issue. Is there a way to indicate in the method definition that I want to return a const?

Community
  • 1
  • 1
James Hogle
  • 3,010
  • 3
  • 22
  • 46

1 Answers1

2

If you want to return a const reference you must declare it.

const TPersistentClass & __fastcall TService_REST_Server_Ol::OnServerMethods()
{
    return __classid(TServerMethods_RSO);
}
Fibbs
  • 1,350
  • 1
  • 13
  • 23