相关疑难解决方法(0)

如何跨指针保持const正确性?

我试图对一个真正const的类进行const操作 - 它不会更改类指向的数据.

例如:

class Node{
public:
    int val;
};
class V{
public:
    Node * node; //what is the change that is needed here?
    void const_action()const{
        node->val=5; //error wanted here
    }
    void action(){
        node->val=5; //error is not wanted here
    }
};
Run Code Online (Sandbox Code Playgroud)

c++ const

5
推荐指数
1
解决办法
331
查看次数

标签 统计

c++ ×1

const ×1