cs1003
#include<iostream>
#include<string>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
class boy
{
    string name;
    int  age;
   public:
    boy(string name,int age)
    {
        name=name;
        age=age;
        this->name=name;//当函数参数和数据成员同名时,函数参数的优先级高,所以优先
        boy::age=age;//访问的是函数参数,利用this 或者作用域来修改

    }
    void get()
    {
        cout<<this->name<<" "<<this->age<<endl;
    }
};
int main()
{
    boy a("guo",22);
    a.get();
    system("pause");
    return 0;
}

 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-02-07
  • 2022-12-23
  • 2021-07-04
  • 2021-09-09
  • 2022-12-23
  • 2022-01-12
猜你喜欢
  • 2021-09-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-15
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案