<> From the story of resume delivery

I didn't plan to use other people's stories today , But I don't know , Technology , dull as ditch water , If we don't even know what we're learning for , What are you learning ? So I think , This entry application scenario is very important .

I went to the interview today , I need to fill in my project experience on my resume , The format is all one :”XXXX - XX - XX, Yes XX project , let XX post , harvest XXXX“···
Obviously , This can be done with a project experience class .

But the experience of this water project comes down , Each experience initializes an instance , What is the system ?
Fortunately, I don't have many projects , It's still pleasant .

At this time , You can consider an example , There are multiple parts , Each avatar modifies its member properties through class methods , How beautiful ? How can we separate ourselves ? There's no skill in separation , If you are not familiar with the copy constructor of a class .

<> copy constructor

People who know constructors generally know that , Constructors are divided into ” Deep structure “ and ” Shallow structure “. If you don't know , You don't have to go anywhere else , Generally speaking, the results will not be very satisfactory , Because I did .

<> Shallow replication

Look at such a chestnut :
class A{}; A *a = new A(); A *b = a;

Pass one object directly to another like this , In general, it is shallow copy , It is a construction mode provided by the system by default . But what are the potential risks of this construction ? Because it's the system , So it can't reach the stack area , therefore , If A There are properties or methods in the heap , Shallow copy is automatically skipped , They are bound to the same address as the original property or method .

How to put it? ? Look at the chestnuts :
class A{ char *a_a; char* changea_a(); }; A *a = new A(); A *b = a;

first , initialization a When I was young , yes a_a Space was allocated ( I won't write the function ), then , take a Shallow copy to b, here ,a String and b In fact, the string of refers to the same block address . here , If passed b Call the function that modifies the string changea_a(), be a The corresponding string will also be modified .

<> Deep replication

What is deep replication ? It must have been very clear , Is explicitly defined , copy constructor .
of course , You can define it explicitly , It's not necessarily deep replication , May be defined or shallow copy .

Look at the whole chestnut :
#include<iostream> #include<string> using namespace std; // Work experience class WorkExp
{ private: string WorkData; string Company; public: WorkExp(){}; string getData(
) { return WorkData; } void setData(string Data) { WorkData = Data; } string
getCom() { return Company; } void setCom(string Com) { Company = Com; } WorkExp(
WorkExp& wep) { WorkData = wep.WorkData; Company = wep.Company; } }; // Resume class
Resume { private: string name; string sex; string age; WorkExp *work; public:
Resume(string name){ this->name = name; work = new WorkExp(); }
//Resume(WorkExp *work) { this->work = work; } Resume(Resume& res) { name = res.
name; age = res.age; sex = res.sex; work = new WorkExp(*res.work); // This is the key point
//work = res.work;// Written like this is shallow copy } // Set up personal information void SetPersonalInfo(string sex,
string age) { this->sex = sex; this->age = age; } void SetWorkExp(string
workData, string Company) { work->setData(workData); work->setCom(Company); }
void show() { cout << " full name :" << this->name << endl << " Gender :"<<this->sex<<endl <<
" Age :"<<this->age<< endl; cout << " work experience :" << work->getData() << " " << " Working company :" <<
work->getCom() << endl; } }; int main() { Resume* a = new Resume(" Ah, vanadium "); a->
SetPersonalInfo("man","22"); a->SetWorkExp("2017 - 2021", "XX university "); Resume b = *a
; b.SetPersonalInfo("girl", "26"); b.SetWorkExp("2021 - 2023", "AA company "); a->show(
); b.show(); return 0; }
<> Prototype mode

I'll finish with the depth of the copy , Prototype mode is actually very simple .

Technology
©2019-2020 Toolsou All rights reserved,
TP6 Application examples of verifier and correct verification data Unity Scene loading asynchronously ( Implementation of loading interface ) Gude Haowen serial - You deserve to be an engineer ( Preface ) Bitcoin in ten years ,VDS Opportunity or fraud Huawei certification HCIA-AI artificial intelligence Image explanation of over fitting and under fitting Python Basic knowledge and notes ESP8266/ESP32 System : Optimize system startup time First knowledge python Skills summary use C++ I want to talk to you “ Prototype mode ” ( copy / copy constructor )