Error: Qualifiers dropped in binding reference of type x to initializer of type y

前端 未结 1 695
一个人的身影
一个人的身影 2020-12-14 18:53

why does the following throw this error:

IntelliSense: qualifiers dropped in binding reference of type \"string &\" to initializer of type \"con

相关标签:
1条回答
  • 2020-12-14 19:27

    By returning a non-const reference to a member of your class, you are giving the caller access to the object as if it's non const. But GetTitle, being a const function, does not have the right to grant that access.

    For example:

    A a;
    string& b = a.GetTitle(); // Allows control over original variable
    
    0 讨论(0)
提交回复
热议问题