BHXSpecter

Does this break encapsulation? REALLY?!

May 10th, 2013
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class CRectangle {
  5.     int x, y;
  6.   public:
  7.     void set_values (int,int);  // setter
  8.     int getX() const { return x; } // getter
  9.     int getY() const { return y; } // getter
  10. };
  11.  
  12. void CRectangle::set_values (int a, int b) {
  13.   x = a;
  14.   y = b;
  15. }
  16.  
  17. int area(int a, int b) { return (a* b); }
  18.  
  19. int main () {
  20.   CRectangle rect;
  21.   int locX, locY;
  22.   rect.set_values (3,4);
  23.   locX = rect.getX();
  24.   locY = rect.getY();
  25.   int rectangleArea = area(locX, locY);
  26.   cout << "area: " << rectangleArea;
  27.   // could have just done this and removed a lot of work
  28.   cout << "area: " << area(rect.getX(), rect.getY());
  29.   return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment