题解 | #构造函数#

构造函数

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;
}

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务