current position:Home>It's always displayed in the formal parameter table. What's the mismatch? I'm dizzy, vs2019

It's always displayed in the formal parameter table. What's the mismatch? I'm dizzy, vs2019

2022-02-04 17:13:53 CSDN Q & A

// Own general array class #pragma once#include<iostream>using namespace std;template<class T>class MyArray{public:    MyArray(int capacity)    {        cout << "MyArray The parameterized construct of calls " << endl;        this->m_Capacity = capacity;        this->m_Size = 0;        this->pAddress = new T[this->m_Capacity];    }    MyArray(const MyArray& arr)    {        count << "MyArry The copy construct of calls " << endl;        this->m_Capacity = arr.m_Capacity;        this->m_Size = arr.m_Size;        this->pAddress=new T[arr.m_Capacity];        for (int i = 0; i < this->m_Size; i++)        {            this->pAddress[i] = arr.pAddress[i];        }    }    MyArray&operator=(const MyArray & arr)    {        cout << "MyArry Of operator= Call to " << endl;        if (this->pAddress != NULL)        {            delete[] this->pAddress;            this->pAddress = NULL;            this->m_Capacity = 0;            this->m_Size = 0;        }        this->m_Capacity = arr.m_Capacity;        this->m_Size = arr.m_Size;        this->pAddress=new T[arr.m_Capacity];        for (int i = 0; i < this->m_Size; i++)        {            this->pAddress[i] = arr.pAddress[i];        }        return *this;    }    ~MyArray()    {        if (this->pAddress != NULL)        {            cout << " Destructor call " << endl;            delete[] this->pAddress;            this->pAddress = NULL;        }    }private:    T * pAddress;// Pointer to the real array opened by the heap     int m_Capacity;// Capacity     int m_Size;// size };



Take the answer :

Copy in constructor
this->m_Capacity = arr.m_Capacity;
It doesn't work that way . Member variables are private ,arr.m_Capacity Such access is not allowed . To add get function


copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/02/202202041713520037.html

Random recommended