'class access control: What if there is readonly access controller?

While I was using class, I found that some attributes, especially the ones which are boolean, are often read by other instances. For example,

class Node{
private:
    int item;
    bool visited;
public:
    bool isVisited(){return visited;}
    void bar(){
        ...
        visited=true;
        ...
    }
};

class Graph{
private:
    vector<Node> nodes;
public:
    void bar(int idx){
        if(nodes[idx].isVidited()){
            ...
            nodes[idx].foo();
            ...
        }
    }
}

In that case if visited is only changed by the methods of the class Node, then the access controller of the attribute visited shouldn't always be private in perspective of reading. What if there is an access controller 'readonly' that is opened to reading, closed to writing? I think that is useful when defining state attributes. Will there be any side effects?



Solution 1:[1]

Have you tried marking the Graph class as friend inside the Node class?

This facilitates accessing the private members of the Node class by the Graph class.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 JuanJeIzquierdo