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