如果我像这样在
一个错误:
为什么编译器在第二种情况下会报错?
const
指针上使用mutable
:
class Test
{
public:
mutable const int* ptr; // OK
};
它正常工作。
但是,如果我像这样使用:
class Test
{
public:
mutable int * const ptr; // Error
};
一个错误:
prog.cpp:6:25: error: const 'ptr' cannot be declared 'mutable'
mutable int * const ptr;
^
prog.cpp: In function 'int main()':
prog.cpp:11:7: error: use of deleted function 'Test::Test()'
Test t;
^
prog.cpp:3:7: note: 'Test::Test()' is implicitly deleted because the default definition would be ill-formed:
class Test
^
prog.cpp:3:7: error: uninitialized const member in 'class Test'
prog.cpp:6:25: note: 'int* const Test::ptr' should be initialized
mutable int * const ptr;
为什么编译器在第二种情况下会报错?