#include <iostream>
using namespace std;

class Test
{
public:
    Test(int _a):a(_a)
    {

    }
    Test& operator=(const Test& ra)
    {
        if(&ra != this)
        {
            const_cast<int &>(a) = ra.a;
        }
        return *this;

    }
    //for test
    int getA()
    {
        return a;
    }
private:
    const int a;
};

int main()
{
    Test a(1);
    cout<< a.getA() <<endl;
    Test b(2);
    cout<< b.getA() <<endl;
    b = a;
    cout<< b.getA() <<endl;
}

相关文章:

  • 2021-12-21
  • 2022-12-23
  • 2021-11-25
  • 2022-03-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-29
猜你喜欢
  • 2021-09-27
  • 2022-01-17
  • 2022-12-23
  • 2022-12-23
  • 2021-11-05
  • 2022-12-23
  • 2021-05-29
相关资源
相似解决方案