当前位置:网站首页>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.
边栏推荐
- Mysql28 database design specification
- pytorch的Dataset的使用
- API learning of OpenGL (2001) gltexgen
- Google login prompt error code 12501
- How to make shell script executable
- MySQL combat optimization expert 05 production experience: how to plan the database machine configuration in the real production environment?
- Advantages and disadvantages of evaluation methods
- 高并发系统的限流方案研究,其实限流实现也不复杂
- Time in TCP state_ The role of wait?
- [untitled]
猜你喜欢

UEditor国际化配置,支持中英文切换

Export virtual machines from esxi 6.7 using OVF tool

Not registered via @EnableConfigurationProperties, marked(@ConfigurationProperties的使用)

MySQL21-用户与权限管理

Adaptive Bezier curve network for real-time end-to-end text recognition

MySQL23-存储引擎

MySQL combat optimization expert 02 in order to execute SQL statements, do you know what kind of architectural design MySQL uses?

Not registered via @enableconfigurationproperties, marked (@configurationproperties use)

Mysql32 lock

Super detailed steps for pushing wechat official account H5 messages
随机推荐
Windchill configure remote Oracle database connection
Complete web login process through filter
MySQL31-MySQL事务日志
Time in TCP state_ The role of wait?
API learning of OpenGL (2005) gl_ MAX_ TEXTURE_ UNITS GL_ MAX_ TEXTURE_ IMAGE_ UNITS_ ARB
Not registered via @EnableConfigurationProperties, marked(@ConfigurationProperties的使用)
Pytorch RNN actual combat case_ MNIST handwriting font recognition
[leectode 2022.2.13] maximum number of "balloons"
Advantages and disadvantages of evaluation methods
【C语言】深度剖析数据存储的底层原理
Global and Chinese markets of static transfer switches (STS) 2022-2028: Research Report on technology, participants, trends, market size and share
ZABBIX introduction and installation
数据库中间件_Mycat总结
软件测试工程师发展规划路线
Mysql34 other database logs
MySQL learning diary (II)
MySQL34-其他数据库日志
16 medical registration system_ [order by appointment]
Anaconda3 installation CV2
Security design verification of API interface: ticket, signature, timestamp