Advertisement
Qwarri

Struct#Qwarri#002

Oct 19th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. struct Character
  6. {
  7. public: // тут объекты к которым мы можем обращаться
  8.         // из внешних функций (которые не входят в структуру)
  9.  
  10.     int returnAge()
  11.     {
  12.         return this->age; // this указывает на то, что переменная age находится в этой же самой структуре
  13.     }
  14.  
  15.     string returnSex()
  16.     {
  17.         return this->sex;
  18.     }
  19.  
  20. private: // К объектам в "private" мы не можем обращаться извне
  21.  
  22.     int age = 19;
  23.     string sex = "male";
  24. };
  25.  
  26. void main()
  27. {
  28.     Character John; // Создаём экземпляр структуры под именем john
  29.  
  30.     cout << John.returnAge() << endl;
  31.     cout << John.returnSex() << endl;
  32.  
  33.     system("pause");
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement