一.学习了什么是模板
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代码