Home Segments Index Top Previous Next

758: Mainline

Accordingly, you might suppose that you should restrict access to those member variables by placing them in the private portion of the class definitions, thereby reducing the risk that you or some other programmer will abuse the values in those member variables accidentally. While you are at it, you might as well put the link constructor in the private portion of the link class, to protect it from abuse as well:

// An interim definition of link; as given, it does not work! 
class link { 
  private: 
    link *next_link_pointer; 
    railroad_car *element_pointer; 
    link (railroad_car *e, link *l) { 
      element_pointer = e; 
      next_link_pointer = l; 
    } 
};