Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <locale.h>
  3.  
  4.  
  5. class Dummy {
  6. public:
  7.  
  8.     Dummy() {
  9.         std::cout << "Вызыван Dummy()" << std::endl;
  10.     }
  11.  
  12.     Dummy(int b) {
  13.         std::cout << "Вызван Dummy(int b)" << std::endl;    
  14.     }
  15.    
  16.     int a;
  17. };
  18.  
  19.  
  20. // Конструктор инициализирует поле 'a' в своем теле
  21. class Test1 {
  22. public:
  23.     Test1() {
  24.         a = 228;
  25.     }
  26.  
  27.     Dummy a;
  28. };
  29.  
  30.  
  31. // Конструктор инициализирует поле 'a' в списке инициализаций
  32. class Test2 {
  33. public:
  34.     Test2(): a(228) {}
  35.    
  36.     Dummy a;
  37. };
  38.  
  39.  
  40.  
  41. int main() {
  42.     setlocale(LC_CTYPE, "rus");
  43.  
  44.     std::cout << "Тест 1: " << std::endl;
  45.     Test1 test1;
  46.  
  47.     std::cout << "\nТест 2: " << std::endl;
  48.     Test2 test2;
  49.  
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement