当前位置:网站首页>15. copy constructor
15. copy constructor
2022-06-13 08:50:00 【zzyzxb】
#include “Time.h”
//void func(Time tmptime)
//{
// return;
//}
Time func()
{
Time linshitime;
return linshitime;
}
int main()
{
// One : copy constructor ( copy constructor )
//int a = 3;
//int b = a; // The act of ordinary copying
// By default , The copy of a class object is to copy each member variable one by one ;
// If the constructor of a class , The first parameter of is the reference of the class type to which it belongs , If there are other additional parameters ,
// Then these additional parameters have default values , Then this constructor is called the copy constructor .
// Function default arguments must be placed in the function declaration , Unless The function has no function declaration
// The function of the copy constructor : At a certain time , Automatically called by the system .
//(1) It is recommended that the first parameter of the copy constructor always carry const
//(2) explicit: Copy constructors are generally not declared as explicit.
// The function of copying member variables one by one is lost because of the existence of our own defined copy constructor
// Or our own " copy constructor " Instead of the default behavior of copying each member variable one by one
//a) If we don't define a copy constructor for the class , The compiler will help us define a " Composite copy constructor ".
//b) If the compiler gives us the synthesized copy constructor , This synthetic copy constructor is also generally used to tmptime Copy each member of to the object being created .
// The type of each member determines how it is copied , For example, if the member variable is an integer , Then copy the value directly .
//c) If you define a copy constructor yourself , Instead of the copy constructor for system composition , This is the time , You have to assign values to class members in your own copy constructor
// To avoid the use of class members without assignment
//Time myTime; // This will call the default constructor ( With no arguments )
//Time myTime2 = myTime; // Called copy constructor
//Time myTime3(myTime); // Called copy constructor
//Time myTime4{ myTime }; // Called copy constructor
//Time myTime5 = { myTime }; // Called copy constructor
//Time myTime6; // This will call the default constructor ( With no arguments )
//myTime6 = myTime5;
// There are also cases where a copy constructor is called
// (1) Pass an object as an argument to a formal parameter of a non reference type
//func(myTime);
// (2) When returning an object from a function
Time mytime = func();
}
边栏推荐
- VBA format word (page, paragraph, table, picture)
- A solution to create a new EXCEL workbook on win10 computer and change the suffix to xlsm (normally it should be xlsx)
- 5、 Constant, variable
- GBase 8a磁盘问题及处理
- H5 mobile terminal adaptation
- About RSA encryption and decryption principle
- Buuctf web (VI)
- JS - print 99 multiplication table of the for cycle case
- 1.初步认识express
- Software Architecture Overview knowledge
猜你喜欢
【Pycharm踩坑记录】配置远程运行后提示,[Errno 2] No such file or directory
[notes] like the solution to the problem of slow query (index + explicitly specifying query fields)
Differences and uses among cookies, localstorage, sessionstorage, and application caching
Shellshock Attack Lab
Knowledge points related to system architecture 1
Browser render passes
Diversified tables through TL table row consolidation
Is signed or unsigned selected to create an integer field in MySQL? The answer is as follows:
JS - simple ATM of the for cycle case
顺时针打印个数组
随机推荐
Replace jade engine with EJS
3、 JS notes
JS - array de duplication in the array object case
Gbase 8A v95 vs v86 compression strategy analogy
【leetcode周赛记录】第80场双周赛记录
Software Architecture Overview knowledge
Mapbox usage, including drawing, loading, modifying, deleting points and faces, displaying pop ups, etc
7、 JS data type
JS - set countdown for Date object case
2020-12-28
Container concept and cloud native
Logstash configuration reference article
JS - max. of array cases
JS string method
Verify the word limit of textarea input box. Only prompt but no submission limit
JS ask for the day of the year
Problèmes et traitement du disque gbase 8a
Screenshot of cesium implementation scenario
1. preliminary understanding of Express
Mapbox loads nationwide and provincial range, displaying multi-color animation points, migration lines, 3D histogram, etc