2024年1月27日学习报告:模板

本文介绍了C++中的函数模板和类模板,包括它们的使用示例。同时提到了明日的学习计划,包括单例模式、工厂模式、右值/移动语义和继续深入研究模板类。
摘要由CSDN通过智能技术生成

一.学习了什么是模板

1.函数模板

#include<iostream>
template<class T>
T fun1(T a, T b)
{
	std::cout << "using template fun"<<std::endl;
	return a * b;
}
int main()
{
	std::cout <<fun1<int>(3, 4);
}

2.类模板

#include<iostream>
template<class T>
class example
{
public:
	example()
	{
		std::cout << "using defaute construct func" << std::endl;
	}
	example(T a, T b)
	{
		std::cout << "using chushihua construct func" << std::endl;


	}
	example(example& other)
	{
		std::cout << "using copy construct func" << std::endl;
		VarOne = other.VarOne;
		VarTwo = other.VarTwo;
	}
	void fun1()
	{
		std::cout << "using template funOne" << std::endl;
	}
	void fun2()
	{
		std::cout << "using template funTwo" << std::endl;
	}
private:
	T VarOne;
	T VarTwo;
	
};
int main()
{
	example<double> exa1;
	exa1.fun1();
	example<int> exa2(1,2);
	exa2.fun2();
	example<int> exa3(exa2);
}

边角料知识点

当构造函数后面加=delete时为禁用

明日学习目标

1.什么是单例模式?

2.什么是工厂模式?

3.什么是右值(移动语义)赋值?

4.继续研究CTPL代码

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值