劳怡月 发表于 2025-6-4 19:57:18

STL学习

手写STL源码

模板

//TemplateDemo
#include<iostream>
using namespace std;
//交换两个变量
void MySwap(int& a, int& b)
{
        int temp = a;
        a = b;
        b = temp;
}
//使用模板--自适应类型生成函数,地址不同
//函数重载和模板函数冲突,优先调用普通函数,或者使用<T>()显示调用
//不支持隐式转换
template<typename T>
void MyTSwap(T& a, T& b)
{
        int temp = a;
        a = b;
        b = temp;
}

int main()
{
        int a = 10;
        int b = 20;
        MyTSwap(a, b);
        MyPrint(a, b);
}操作符重载

class Complex{public:        double real;        double image;        Complex(double real, double image) :real(real), image(image) {}        Complex Add(Complex& other)        {                return Complex(this->real + other.real, this->image + other.real);        }        Complex Mulitply(Complex& other)        {                double a = this->real;                double b = this->image;                double c = other.real;                double d = other.image;                return Complex(a * c - b * d, b * c + a * d);        }        Complex operator+(Complex& other)        {                return Complex(this->real + other.real, this->image + other.real);        }        Complex operator*(Complex& other)        {                double a = this->real;                double b = this->image;                double c = other.real;                double d = other.image;                return Complex(a * c - b * d, b * c + a * d);        }};ostream& operator

酝垓 发表于 2025-11-25 23:25:46

不错,里面软件多更新就更好了

吉芷雁 发表于 2025-12-11 08:50:38

这个好,看起来很实用

后仲舒 发表于 2026-1-16 02:04:34

新版吗?好像是停更了吧。

篁瞑普 发表于 2026-1-16 17:45:50

感谢发布原创作品,程序园因你更精彩

杼氖 发表于 2026-1-17 08:42:39

很好很强大我过来先占个楼 待编辑

荦绅诵 发表于 2026-1-17 23:49:08

感谢发布原创作品,程序园因你更精彩

康器 发表于 2026-1-20 03:19:29

前排留名,哈哈哈

玛凶 发表于 2026-1-24 07:35:51

前排留名,哈哈哈

栓州 发表于 2026-1-26 10:44:14

yyds。多谢分享

森萌黠 发表于 2026-1-28 04:06:05

感谢,下载保存了

娥搽裙 发表于 2026-1-28 12:41:18

谢谢分享,辛苦了

辅箱肇 发表于 2026-1-28 13:34:37

这个有用。

瞪皱炕 发表于 2026-1-29 01:56:51

感谢分享,下载保存了,貌似很强大

班嘉淑 发表于 2026-1-29 05:34:28

鼓励转贴优秀软件安全工具和文档!

百杲憔 发表于 2026-1-31 05:46:08

感谢,下载保存了

訾懵 发表于 2026-2-4 14:09:03

感谢发布原创作品,程序园因你更精彩

挫莉虻 发表于 2026-2-4 18:11:47

感谢,下载保存了

猷浮 发表于 2026-2-7 22:51:50

谢谢楼主提供!

倘伟 发表于 2026-2-8 08:03:58

前排留名,哈哈哈
页: [1] 2
查看完整版本: STL学习