1 Star 0 Fork 0

Admin / text_cpp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
class_project2_3.cpp 1.34 KB
一键复制 编辑 原始数据 按行查看 历史
Admin 提交于 2024-04-23 14:03 . 运算符重载
#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;
}
1
https://gitee.com/small-c_2_0/text_cpp.git
git@gitee.com:small-c_2_0/text_cpp.git
small-c_2_0
text_cpp
text_cpp
master

搜索帮助