C + + sub-file definition deep copy and shallow copy

Source: Internet
Author: User
Tags shallow copy

1.

#include <stdlib.h> #include <iostream> #include "Array.h" using namespace Std;int main (void) {Array arr1; Arr1.setcount (5); Array arr2 (ARR1);//~array ();cout<< "Arr2.m_icount:" <<arr2.getcount () <<endl;system ("pause"); return 0;}

2.

#include "Array.h" #include <iostream>using namespace std; Array::array () {cout<< "Array" <<ENDL;} Array::array (const array & arr) {m_icount=arr.m_icount;cout<< "Array &" <<ENDL;} Array::~array () {cout << "~array" <<ENDL;} void Array::setcount (int count) {M_icount=count;} int Array::getcount () {return m_icount;}

3.

Class Array{public:array ();//default constructor Array (const array &arr);//copy constructor ~array (); void SetCount (int count); int GetCount ();p rivate:int m_icount;};

Operation Result:

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M02/06/1D/wKiom1mx_R-xJ2zzAAASKiP0x90212.png "title=" Untitled. png "alt=" Wkiom1mx_r-xj2zzaaaskip0x90212.png "/>


C + + sub-file definition deep copy and shallow copy

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.