Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- struct Character
- {
- public: // тут объекты к которым мы можем обращаться
- // из внешних функций (которые не входят в структуру)
- int returnAge()
- {
- return this->age; // this указывает на то, что переменная age находится в этой же самой структуре
- }
- string returnSex()
- {
- return this->sex;
- }
- private: // К объектам в "private" мы не можем обращаться извне
- int age = 19;
- string sex = "male";
- };
- void main()
- {
- Character John; // Создаём экземпляр структуры под именем john
- cout << John.returnAge() << endl;
- cout << John.returnSex() << endl;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement