#include
int* p_n;
class A
{
public:
A(int val) : n(val)
{
// At this point the compiler does not know if the object is const or not.
p_n = &n;
}
int n;
};
int main()
{
// A::n is const, because A is const, right?
const A a(1);
// but we change a const value here
*p_n = 2;
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/79421784/assigning-a-value-to-a-const-class-member[/url]