Tranvick

Example8

Jan 8th, 2013
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. //Пример 8. Классы:
  2. //конструкторы и деструкторы; виртуализация; конструктор копирования
  3.  
  4. #include <iostream>
  5.  
  6. using namespace std;
  7.  
  8. class MyClass {
  9. private:
  10.     int field;
  11. public:
  12.     MyClass() : field(0) {}
  13.     MyClass(int x) {
  14.         field = x;
  15.     }
  16.     MyClass(const MyClass &);
  17.     virtual ~MyClass() {}
  18.     void print() {
  19.         cout << field << endl;
  20.     }
  21. };
  22.  
  23. MyClass :: MyClass (const MyClass & q) {
  24.     field = q.field;
  25. }
  26.  
  27. int main() {
  28.     MyClass A;
  29.     MyClass B(10);
  30.     MyClass C(B);
  31.     A.print();
  32.     B.print();
  33.     C.print();
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment