【问题标题】:Clang: Binding of reference to a value of type 'const TClass' drops qualifiersClang:将引用绑定到“const TClass”类型的值会丢弃限定符
【发布时间】:2015-11-29 17:56:44
【问题描述】:

我有以下方法,使用“经典”bcc32 编译器编译良好,但使用 Rad Studio 10 Clang 编译器编译失败。

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

编译器产生以下错误:

[CLANG 错误] Service_REST_Server_OlU.cpp(37):对类型“TPersistentClass”(又名“System::TMetaClass *”)的引用绑定到“const TClass”类型的值(又名“System::TMetaClass *const” ') 删除限定符

如果我理解正确,基于this question,这不起作用的原因是代码试图返回对 const 对象的非常量引用。但是,我不确定如何在语法上解决这个问题。有没有办法在方法定义中指出我要返回const

【问题讨论】:

    标签: c++ c++11 clang c++builder c++builder-10-seattle


    【解决方案1】:

    如果你想返回一个常量引用,你必须声明它。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-13
      • 2014-02-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多