Why can't I declare a reference to a mutable object? (“reference cannot be declared mutable”)

前端 未结 4 620
别那么骄傲
别那么骄傲 2021-02-05 04:04

Let\'s say we have a test.cpp as follows:

class A;

class B
{
    private:
        A mutable& _a;
};

Compilation:



        
4条回答
  •  臣服心动
    2021-02-05 05:05

    According to the standard: [7.1.1 para 8]:

    "The mutable specifier can be applied only to names of class data members (9.2) and cannot be applied to names declared const or static, and cannot be applied to reference members."

    So it's just illegal.

提交回复
热议问题