当前位置:网站首页>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.
边栏推荐
- Jar runs with error no main manifest attribute
- MySQL21-用户与权限管理
- 评估方法的优缺点
- 用于实时端到端文本识别的自适应Bezier曲线网络
- Global and Chinese market of thermal mixers 2022-2028: Research Report on technology, participants, trends, market size and share
- [programmers' English growth path] English learning serial one (verb general tense)
- [after reading the series of must know] one of how to realize app automation without programming (preparation)
- MySQL实战优化高手09 生产经验:如何为生产环境中的数据库部署监控系统?
- ① BOKE
- Const decorated member function problem
猜你喜欢
实现以form-data参数发送post请求
MySQL29-数据库其它调优策略
Pytoch LSTM implementation process (visual version)
Unicode decodeerror: 'UTF-8' codec can't decode byte 0xd0 in position 0 successfully resolved
Mysql32 lock
Moteur de stockage mysql23
Mysql24 index data structure
15 medical registration system_ [appointment registration]
Const decorated member function problem
Ueeditor internationalization configuration, supporting Chinese and English switching
随机推荐
Mysql27 index optimization and query optimization
Security design verification of API interface: ticket, signature, timestamp
MySQL30-事务基础知识
MySQL26-性能分析工具的使用
Software test engineer development planning route
MySQL21-用户与权限管理
Database middleware_ MYCAT summary
MySQL實戰優化高手04 借著更新語句在InnoDB存儲引擎中的執行流程,聊聊binlog是什麼?
Use JUnit unit test & transaction usage
Opencv uses freetype to display Chinese
MySQL实战优化高手11 从数据的增删改开始讲起,回顾一下Buffer Pool在数据库里的地位
How to build an interface automation testing framework?
Windchill configure remote Oracle database connection
Mysql35 master slave replication
MySQL底层的逻辑架构
Pytorch RNN actual combat case_ MNIST handwriting font recognition
Time complexity (see which sentence is executed the most times)
Global and Chinese market of operational amplifier 2022-2028: Research Report on technology, participants, trends, market size and share
API learning of OpenGL (2003) gl_ TEXTURE_ WRAP_ S GL_ TEXTURE_ WRAP_ T
Mysql23 storage engine