题解 | #构造函数#
构造函数
https://www.nowcoder.com/practice/2809d720c7024f959b283f8444d9bdc9
#include <iostream> #include <string> using namespace std; class Person{ public: Person(){} Person(string name,int age) { this->m_name = name; this->m_age = age; } void showPerson() { cout << this->m_name << " " << this->m_age << endl; } string m_name; int m_age; }; int main() { string name; int age; cin >> name; cin >> age; Person p(name,age); p.showPerson(); return 0; }