当前位置:网站首页>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.
边栏推荐
- API learning of OpenGL (2001) gltexgen
- Emotional classification of 1.6 million comments on LSTM based on pytoch
- 基于Pytorch肺部感染识别案例(采用ResNet网络结构)
- In fact, the implementation of current limiting is not complicated
- Mysql32 lock
- 该不会还有人不懂用C语言写扫雷游戏吧
- Global and Chinese market of wafer processing robots 2022-2028: Research Report on technology, participants, trends, market size and share
- Global and Chinese market of operational amplifier 2022-2028: Research Report on technology, participants, trends, market size and share
- ZABBIX introduction and installation
- MySQL25-索引的创建与设计原则
猜你喜欢
MySQL實戰優化高手04 借著更新語句在InnoDB存儲引擎中的執行流程,聊聊binlog是什麼?
In fact, the implementation of current limiting is not complicated
MySQL combat optimization expert 03 uses a data update process to preliminarily understand the architecture design of InnoDB storage engine
Mysql26 use of performance analysis tools
UEditor国际化配置,支持中英文切换
Not registered via @enableconfigurationproperties, marked (@configurationproperties use)
The underlying logical architecture of MySQL
How to find the number of daffodils with simple and rough methods in C language
Mysql32 lock
MySQL Real Time Optimization Master 04 discute de ce qu'est binlog en mettant à jour le processus d'exécution des déclarations dans le moteur de stockage InnoDB.
随机推荐
软件测试工程师必备之软技能:结构化思维
MySQL Real Time Optimization Master 04 discute de ce qu'est binlog en mettant à jour le processus d'exécution des déclarations dans le moteur de stockage InnoDB.
Water and rain condition monitoring reservoir water and rain condition online monitoring
MySQL实战优化高手05 生产经验:真实生产环境下的数据库机器配置如何规划?
MySQL实战优化高手11 从数据的增删改开始讲起,回顾一下Buffer Pool在数据库里的地位
MySQL20-MySQL的数据目录
Google login prompt error code 12501
C language string function summary
保姆级手把手教你用C语言写三子棋
Mysql26 use of performance analysis tools
API learning of OpenGL (2005) gl_ MAX_ TEXTURE_ UNITS GL_ MAX_ TEXTURE_ IMAGE_ UNITS_ ARB
MySQL 29 other database tuning strategies
[programmers' English growth path] English learning serial one (verb general tense)
15 medical registration system_ [appointment registration]
MySQL28-数据库的设计规范
MySQL实战优化高手10 生产经验:如何为数据库的监控系统部署可视化报表系统?
[paper reading notes] - cryptographic analysis of short RSA secret exponents
A necessary soft skill for Software Test Engineers: structured thinking
Mysql27 - Optimisation des index et des requêtes
MySQL24-索引的数据结构