当前位置:网站首页>Copy constructor template and copy assignment operator template
Copy constructor template and copy assignment operator template
2022-07-06 10:38:00 【pickled cabbage】
#include <iostream>
#include <string>
using namespace std;
template <typename T1>
class A
{
public:
// Constructor template
template <typename T2>
A(T2 v1, T2 v2);
// Member function template
template <typename T3>
void myft(T3 tmpt)
{
cout << tmpt << endl;
}
T1 m_ic;
static constexpr int m_stcvalue = 200;
public:
A(double v1, double v2)
{
cout << "A(double v1, double v2)" << endl;
}
A(T1 v1, T1 v2)
{
cout << "A(T1 v1, T1 v2)" << endl;
}
public:
// Copy constructor template
template <typename U>
A(const A<U>& other)
//A(A<U>& other)
{
cout << "A::A(const A<U>& other)" << endl;
}
// Copy assignment operator template
template <typename U>
A<T1>& operator=(const A<U>& other)
//A<T1>& operator=(A<U>& other)
{
cout << "operator=(const A<U>& other)" << endl;
return *this;
}
};
// Off class definition
template <typename T1>
template <typename T2>
A<T1>::A(T2 v1, T2 v2)
{
cout << "A::A(T2,T2) Yes !" << endl;
}
int main()
{
A<float> a(11.1f, 12.2f);
a.m_ic = 16.2f;
A<float> a1(a);
return 0;
}
// If the parameters of copy constructor template and copy assignment operator template are not const, Will not call .
If you bring it const, And make corresponding calls , So here a1 The type of needs to be similar to a Different types of , For example int.
边栏推荐
猜你喜欢
MySQL26-性能分析工具的使用
MySQL21-用户与权限管理
Mysql30 transaction Basics
Super detailed steps for pushing wechat official account H5 messages
Database middleware_ MYCAT summary
MySQL29-数据库其它调优策略
Opencv uses freetype to display Chinese
MySQL30-事务基础知识
Introduction tutorial of typescript (dark horse programmer of station B)
MySQL27-索引优化与查询优化
随机推荐
Mysql25 index creation and design principles
How to change php INI file supports PDO abstraction layer
[leectode 2022.2.13] maximum number of "balloons"
UEditor国际化配置,支持中英文切换
MySQL32-锁
评估方法的优缺点
Implement context manager through with
MySQL实战优化高手04 借着更新语句在InnoDB存储引擎中的执行流程,聊聊binlog是什么?
Isn't there anyone who doesn't know how to write mine sweeping games in C language
A necessary soft skill for Software Test Engineers: structured thinking
15 medical registration system_ [appointment registration]
[Julia] exit notes - Serial
Mysql24 index data structure
MySQL transaction log
实现微信公众号H5消息推送的超级详细步骤
How to build an interface automation testing framework?
基于Pytorch肺部感染识别案例(采用ResNet网络结构)
第一篇博客
【C语言】深度剖析数据存储的底层原理
Mysql23 storage engine