Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2011
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. //-----------'Optimized' version
  2.  
  3. #include <iostream>
  4.  
  5. class Thing {
  6.    public:
  7.       int getX() const;
  8.       void setX(const int x);
  9.    private:
  10.       int x;
  11. };
  12.  
  13. inline int Thing::getX() const {
  14.    return x;
  15. }
  16.  
  17. inline void Thing::setX(const int x) {
  18.    this->x = x;
  19. }
  20.  
  21. inline void printMe(const Thing& thing) {
  22.    std::cout << thing.getX() << "\n";
  23. }
  24.  
  25. int main() {
  26.    Thing thing;
  27.    thing.setX(123);
  28.    printMe(thing);
  29. }
  30.  
  31.  
  32. //-------------Lazy programmer
  33.  
  34. #include <iostream>
  35.  
  36. class Thing {
  37.    public:
  38.       int getX() ;
  39.       void setX(int x);
  40.    private:
  41.       int x;
  42. };
  43.  
  44. inline int Thing::getX() {
  45.    return x;
  46. }
  47.  
  48. inline void Thing::setX(int x) {
  49.    this->x = x;
  50. }
  51.  
  52. inline void printMe(Thing thing) {
  53.    std::cout << thing.getX() << "\n";
  54. }
  55.  
  56. int main() {
  57.    Thing thing;
  58.    thing.setX(123);
  59.    printMe(thing);
  60. }
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement