小编Mar*_*tin的帖子

为什么我不能声明对可变对象的引用?("引用不能声明为可变")

假设我们有test.cpp以下内容:

class A;

class B
{
    private:
        A mutable& _a;
};
Run Code Online (Sandbox Code Playgroud)

汇编:

$> gcc test.cpp
test.cpp:6:20: error: reference ‘_a’ cannot be declared ‘mutable’ [-fpermissive]
Run Code Online (Sandbox Code Playgroud)

我的gcc:

$> gcc --version
gcc (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Run Code Online (Sandbox Code Playgroud)

为什么?

c++ reference

26
推荐指数
4
解决办法
1万
查看次数

标签 统计

c++ ×1

reference ×1