Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Oct 2nd, 2011  |  syntax: C++  |  size: 0.85 KB  |  views: 57  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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.