代码拉取完成,页面将自动刷新
#include <iostream>
using namespace std;
/*
Date(Date& b)//拷贝构造
{
_year = b._year;
_month = b._month;
_day = b._day;
cout << "Date(Date& b)" << endl;
}
Date& operator=(Date b)
{
_year = b._year;
_month = b._month;
_day = b._day;
return b;
}
void Printf()
{
cout << _year << "-" << _month << "-" << _day << endl;
}
private:
int _year;
int _month;
int _day;
};
int main()
{
Date a(2024, 4, 1);
Date b;
Date c;
c = b = a;
c.Printf();
//b = a;
return 0;
}*/
/*class Date
{
public:
Date(int year = 1, int month = 1, int day = 1)//默认构造函数
{
_year = year;
_month = month;
_day = day;
cout << "Date()" << endl;
}
Date(Date& b)//拷贝构造
{
_year = b._year;
_month = b._month;
_day = b._day;
cout << "Date(Date& b)" << endl;
}
void operator=(Date b)//赋值重载
{
_year = b._year;
_month = b._month;
_day = b._day;
}
void Printf()
{
cout << _year << "-" << _month << "-" << _day << endl;
}
private:
int _year;
int _month;
int _day;
};
Date func()
{
Date b(2024, 4, 1);//引用返回
return b;
}
int main()
{
const Date& a = func();
return 0;
}*/
class A
{
public:
A(int a1 = 1)//构造函数
{
_a1 = a1;
}
int operator+(A b)
{
return b._a1 + _a1;
}
void Printf()
{
cout << _a1 << endl;
}
private:
int _a1;
};
void Text()
{
A a(2);
a.Printf();
}
int main()
{
Text();
return 0;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。