Get the App
SLTechnology News&Howtos  ›  Development  › 

How to analyze the deep and shallow copy of PYTHON from the perspective of C++

Shulou Source: shulou.com Published: 2022-06-02 09:25:10 09月16日 Update

This article mainly explains "how to analyze the deep and shallow copy of PYTHON from the perspective of C++". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to analyze the deep and shallow copy of PYTHON from the perspective of C++".

Seeing a deep and shallow copy of the list of python today, I can't help comparing it with C\ C++ as follows:

In fact, the deep COPY and the shallow COPY in python are the same as those in C\ C++. After all, the bottom layer of python is made by Cpicket +, and this aspect is retained.

C\ C++ principle, for the class or structure copy constructor equal sign (=) operator to retain the shallow COPY, of course, we can customize

These functions. Let's start with C++ 's simple example of the copy constructor equal sign (=) operator.

# include#include # include using namespace std;class testcy {private: char* a; unsigned int b; public: testcy (const char* inc) {a = new char [strlen (inc) + 1]; strcpy (aQuininc); b = 1 } testcy () {a = NULL; b = 0;} testcy (const testcy & in) / / shallow copy constructor {this- > a = in.a This- > b = in.b;} testcy& operator= (const testcy& in) / / shallow = value operator overload {this- > a = in.a; this- > b = in.b } void print () {cout

Tags: Cantilever copy function depth data angle analysis memory pointer that is pointing operator learning content principle practice theory equal sign problem not only Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Linux OPPO Reno Xiaomi Microsoft