<<<Index>>>

More access control examples



// point.h
class Point
{
private:
    int m_x;
    int m_y;
    void reset_coord();
public:
    double distance_to_origin();
    double distance_to_point();
};


// point.cpp
double Point::distance_to_point( Point other )
{
    // Access to private members m_x, m_y is allowed,
    // because we are in a member function:
    double x_diff = m_x - other.m_x;
    double y_diff = m_y - other.m_y;
    return sqrt( x_diff * x_diff + y_diff * y_diff );
}

<<<Index>>>