小格 2019-06-01 19:18 采纳率: 0%
浏览 167

调用类模板生成类函数时参数不匹配

#include<iostream>
#include<stdlib.h>
using namespace std;
template< typename T >
class  Array
{
public:
    Array(int s);
    virtual ~Array();
    virtual const T& Entry(int index) const;
    virtual void Enter(int index, const T & value);
protected:
    int size;
    T * element;
};
template<typename T> Array<T>::Array(int s)
{
    if (s > 1) size = s;
    else size = 1;
    element = new T[size];
}
template < typename T > Array < T > :: ~Array()
{
    delete[] element;
}
template < typename T > const T& Array < T > ::Entry(int index) const
{
    return  element[index];
}
template < typename T > void Array < T > ::Enter(int index, const T& value)
{
    element[index] = value;
}
template < typename T >


class BoundArray : public Array < T >
{
public:
    BoundArray(int low = 0, int height = 1) :Array(height - low + 1)
    {
        if (height - low < 0)
        {
            cout << "Beyond the bounds of Array.\n";
            exit(1);
        }
        min = low;
    }
    virtual const T & Entry(int index) const
    {
        if (index < min || index > min + size - 1)
        {
            cout << "Beyond the bounds of index.\n";
            exit(1);
        }
        return Array<T>::Entry(index - min);
    }
    virtual void Enter(int index, const T& value)
    {
        if (index < min || index > min + size - 1)
        {
            cout << "Beyond the bounds of index.\n";
            exit(1);
        }
        Array<T>::Enter(index - min, value);
    }
protected:
    int min;
};


int main()
{
    int i;
    int low = 1, height = 10;
    BoundArray<int> b(low, height);
    for (i = low; i <= height; i++)
        b.Enter(i, i * 2);
    cout << "BoundArray: \n";
    for (i = low; i <= height; i++)
    {
        cout << "b[" << i << "] = " << b.Entry(i) << "\t";
        if (i % 5 == 0)cout << endl;
    }
}

图片说明

哪位大神能帮忙看看应该怎么改吗

  • 写回答

1条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2022-09-20 19:39
    关注
    不知道你这个问题是否已经解决, 如果还没有解决的话:

    如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^
    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记