当前位置:网站首页>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.
边栏推荐
- Baidu Encyclopedia data crawling and content classification and recognition
- MySQL combat optimization expert 10 production experience: how to deploy visual reporting system for database monitoring system?
- 如何搭建接口自动化测试框架?
- Mysql36 database backup and recovery
- 百度百科数据爬取及内容分类识别
- MySQL26-性能分析工具的使用
- Implement context manager through with
- How to change php INI file supports PDO abstraction layer
- 该不会还有人不懂用C语言写扫雷游戏吧
- Sed text processing
猜你喜欢

Export virtual machines from esxi 6.7 using OVF tool
![15 medical registration system_ [appointment registration]](/img/c1/27c7a5aae82783535e5467583bb176.png)
15 medical registration system_ [appointment registration]

MySQL transaction log

ZABBIX introduction and installation

基于Pytorch的LSTM实战160万条评论情感分类

Database middleware_ MYCAT summary

数据库中间件_Mycat总结

The underlying logical architecture of MySQL

Isn't there anyone who doesn't know how to write mine sweeping games in C language

Solve the problem of remote connection to MySQL under Linux in Windows
随机推荐
MySQL27-索引优化与查询优化
MySQL combat optimization expert 05 production experience: how to plan the database machine configuration in the real production environment?
用于实时端到端文本识别的自适应Bezier曲线网络
Typescript入门教程(B站黑马程序员)
February 13, 2022-2-climbing stairs
Use JUnit unit test & transaction usage
Good blog good material record link
Security design verification of API interface: ticket, signature, timestamp
MySQL transaction log
MySQL实战优化高手07 生产经验:如何对生产环境中的数据库进行360度无死角压测?
API learning of OpenGL (2005) gl_ MAX_ TEXTURE_ UNITS GL_ MAX_ TEXTURE_ IMAGE_ UNITS_ ARB
Mysql24 index data structure
15 medical registration system_ [appointment registration]
MySQL real battle optimization expert 11 starts with the addition, deletion and modification of data. Review the status of buffer pool in the database
Adaptive Bezier curve network for real-time end-to-end text recognition
How to change php INI file supports PDO abstraction layer
基于Pytorch的LSTM实战160万条评论情感分类
Water and rain condition monitoring reservoir water and rain condition online monitoring
数据库中间件_Mycat总结
Mysql35 master slave replication