取地址及 const取地址操作符重载
#include <iostream>
using namespace std;
class A
{
public:
A(int year, int month, int day)
{
_year = year;
_month = month;
_day = day;
}
A* operator&()
{
return nullptr;
}
const A* operator&()const
{
return nullptr;
}
void Print()
{
cout << _year << "/" << _month << "/" << _day << endl;
}
void Print()const
{
cout << _year << "/" << _month << "/" << _day << endl;
}
private:
int _year;
int _month;
int _day;
};
int main()
{
A d1(2023, 8, 8);
const A d2(2023, 9, 1);
d1.Print();
d2.Print();
cout << &d1 << endl;
cout << &d2 << endl;
return 0;
}