1 Star 0 Fork 0

Admin / text_cpp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
class_project2_2.cpp 1.37 KB
一键复制 编辑 原始数据 按行查看 历史
Admin 提交于 2024-04-22 17:48 . 析构函数,拷贝构造
#include <iostream>
using namespace std;
/*class Stack
{
public:
Stack()
{
_arr = nullptr;
_capacity = 0;
_size = 0;
}
~Stack()
{
free(_arr);
_arr = nullptr;
_capacity = _size = 0;
cout << "~Stack()" << endl;
}
private:
int* _arr;
int _capacity;
int _size;
};*/
/*class Date
{
public:
Date(int year = 1, int month = 1,int day = 1)//ĬϹ캯
{
_year = year;
_month = month;
_day = day;
}
Date(const 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;
};*/
/*int main()
{
/*Date a1(2024, 1, 2);
//Date b1(a1);
Date b1 = a1;
b1.Printf();*/
/*return 0;
}*/
/*class A
{
public:
A(int add = 0)
{
_add = add;
}
void Printf()
{
cout << _add << endl;
}
private:
int _add;
};
int main()
{
A a1(3);
A a2 = a1;
a2.Printf();
return 0;
}*/
class Stack
{
public:
Stack(int capacity,int size)
{
_arr = (int*)malloc(sizeof(int)*capacity);
_capacity = capacity;
_size = size;
}
Stack(const Stack& b)
{
_arr = (int*)malloc(sizeof(int) * (b._capacity));
_capacity = b._capacity;
_size = b._size;
}
void Printf()
{
cout << _capacity << "-" << _size << endl;
}
private:
int* _arr;
int _capacity;
int _size;
};
int main()
{
Stack a(2, 1);
Stack b = a;
b.Printf();
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

搜索帮助