#include <iostream>

using namespace std;

class Base
{
public:
    Base(int x) : x(x)//成员初始化列表中不需要也不能够用this指针指出数据成员
    {

    }

    int x;
};

class Base1
{
public:
    Base1(int x)
    {
        this->x = x;//函数体里赋值时必须用this指明那个是类的数据成员
    }

    int x;
};


int main()
{
    Base b(4);
    cout << b.x << endl;

    return 0;
}

  

相关文章:

  • 2022-12-23
  • 2021-09-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-03
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-03
  • 2022-02-27
  • 2022-12-23
  • 2022-12-23
  • 2021-10-02
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案