海超人and大洋游侠 2021-10-09 17:28 采纳率: 33.3%
浏览 348
已结题

一直显示在形参表中不匹配啥情况啊,我晕了,vs2019


//自己的通用的数组类
#pragma once
#include<iostream>
using namespace std;
template<class T>
class MyArray
{
public:
    MyArray(int capacity)
    {
        cout << "MyArray的有参构造调用" << endl;
        this->m_Capacity = capacity;
        this->m_Size = 0;
        this->pAddress = new T[this->m_Capacity];
    }
    MyArray(const MyArray& arr)
    {
        count << "MyArry的拷贝构造调用" << 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的operator=的调用" << 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 << "析构函数调用" << endl;
            delete[] this->pAddress;
            this->pAddress = NULL;
        }
    }
private:
    T * pAddress;//指针指向堆区开辟的真实数组
    int m_Capacity;//容量
    int m_Size;//大小
};
  • 写回答

1条回答 默认 最新

  • CSDN专家-link 2021-10-09 17:32
    关注

    拷贝构造函数中
    this->m_Capacity = arr.m_Capacity;
    这么写不行啊。成员变量都是私有的,arr.m_Capacity这么访问不可以。要加get函数

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 10月17日
  • 已采纳回答 10月9日
  • 创建了问题 10月9日

悬赏问题

  • ¥15 请问有会的吗,用MATLAB做
  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 ARIMA模型时间序列预测用pathon解决
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序,怎么查看客户esp32板子上程序及烧录地址
  • ¥50 html2canvas超出滚动条不显示