当前位置:网站首页>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.
边栏推荐
- 16 medical registration system_ [order by appointment]
- Use JUnit unit test & transaction usage
- ByteTrack: Multi-Object Tracking by Associating Every Detection Box 论文阅读笔记()
- Global and Chinese markets for aprotic solvents 2022-2028: Research Report on technology, participants, trends, market size and share
- 解决在window中远程连接Linux下的MySQL
- MySQL35-主从复制
- 在jupyter NoteBook使用Pytorch进行MNIST实现
- 软件测试工程师必备之软技能:结构化思维
- Mysql23 storage engine
- MySQL real battle optimization expert 11 starts with the addition, deletion and modification of data. Review the status of buffer pool in the database
猜你喜欢

如何搭建接口自动化测试框架?

MySQL20-MySQL的数据目录

MySQL30-事务基础知识

MySQL24-索引的数据结构

Implement sending post request with form data parameter

Pytorch LSTM实现流程(可视化版本)

MySQL实战优化高手11 从数据的增删改开始讲起,回顾一下Buffer Pool在数据库里的地位

实现微信公众号H5消息推送的超级详细步骤

Security design verification of API interface: ticket, signature, timestamp

UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xd0 in position 0成功解决
随机推荐
MySQL combat optimization expert 07 production experience: how to conduct 360 degree dead angle pressure test on the database in the production environment?
Implement sending post request with form data parameter
Case identification based on pytoch pulmonary infection (using RESNET network structure)
MySQL36-数据库备份与恢复
好博客好资料记录链接
pytorch的Dataset的使用
C language string function summary
Good blog good material record link
Use xtrabackup for MySQL database physical backup
Mysql35 master slave replication
MySQL combat optimization expert 03 uses a data update process to preliminarily understand the architecture design of InnoDB storage engine
MySQL底层的逻辑架构
MySQL实战优化高手11 从数据的增删改开始讲起,回顾一下Buffer Pool在数据库里的地位
Global and Chinese market for intravenous catheter sets and accessories 2022-2028: Research Report on technology, participants, trends, market size and share
UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xd0 in position 0成功解决
MySQL实战优化高手03 用一次数据更新流程,初步了解InnoDB存储引擎的架构设计
评估方法的优缺点
Global and Chinese market of transfer switches 2022-2028: Research Report on technology, participants, trends, market size and share
Google login prompt error code 12501
MySQL combat optimization expert 06 production experience: how does the production environment database of Internet companies conduct performance testing?