Advertisement
framp

Constructor, Destructors, Whatever

Mar 29th, 2012
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.01 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Test01 {
  6.     public:
  7.         int value;
  8.         Test01(int v=0): value(v) { cout << "Test01 " << value << " Constructor;\n"; }
  9.         Test01(const Test01 &T): value(T.value) { cout << "Test01 " << value << " Copy Constructor;\n"; }
  10.         ~Test01(){ cout << "Test01 " << value << " Destructor;\n"; }
  11.         Test01 & operator= (const Test01 &T){ cout << "Test01 " << value << "  Assignment Operator;\n"; value = T.value; return *this; }
  12. };
  13.  
  14. class Test02 : public Test01 {
  15.     public:
  16.         Test02(int v=0): Test01(v){ cout << "Test02 " << value << " Constructor;\n"; }
  17.         //Test02(const Test02 &T){ cout << "Test02 " << value << " Copy Constructor;\n"; }
  18.         ~Test02(){ cout << "Test02 " << value << " Destructor;\n"; }
  19. };
  20.  
  21. template<class T>
  22. T * pointer(T* v){
  23.     v->value++;
  24.     return v;
  25. }
  26. template<class T>
  27. T & reference(T& v){
  28.     v.value++;
  29.     return v;
  30. }
  31. template <class T>
  32. T value(T v){
  33.     v.value++;
  34.     return v;
  35. }
  36.  
  37. int main(){
  38.     cout << "GETTING YO SHIT READY, MAN\n";
  39.     Test02 a(3), b(5);
  40.     Test02 c = a;
  41.     cout << "HERE YA GO\n"
  42.          << "a: " << a.value << "\n"
  43.          << "b: " << b.value << "\n"
  44.          << "c: " << c.value << "\n";
  45.    
  46.     cout << "TESTING SOME WEIRD NEW SHIT\n"
  47.          << "Passing by POINTER (nothing)\n";
  48.     pointer(&a);
  49.     cout << "Passing by REFERENCE (still nothing, this is so GAY)\n";
  50.     reference(b);
  51.     cout << "Passing by VALUE\n";
  52.     value(c);
  53.    
  54.     cout << "The path of the righteous man is beset on all sides by the inequities of the selfish and the tyranny of evil men. Blessed is he who, in the name of charity and good will, shepherds the weak through the valley of the darkness. For he is truly his brother's keeper and the finder of lost children. And I will strike down upon thee with great vengeance and furious anger those who attempt to poison and destroy my brothers. AND YOU WILL KNOW I AM THE LORD WHEN I LAY MY VENGEANCE UPON YOU.\n\n";
  55.    
  56.     cout << "THE END\n"
  57.          << "No.. wait.. dafuq? DESTRUCTORS!\n"
  58.          << "HIDE YO KIDS, HIDE YO WIFE CAUSE THEY'RE DESTRUCTING EVERYBODY OUT THERE\n\n";
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement