-->
当前位置:首页 > 题库 > 正文内容

程序填空题:A Fill in the blanks

Luz4年前 (2021-05-10)题库4226
```
#include
using namespace std;
class IndexError{};
template @@[](2)
class ARRAY
{
size_t m_size;
T *m_ptr;
public:
ARRAY(size_t size) : m_size(size)
{
m_ptr = new T[size];
memset(m_ptr, 0, size*sizeof(int));
}
~ARRAY()
{
delete[] m_ptr;
}
T& at(int index);
};

template
@@[T&ARRAY](2)::at(int index)
{
if(index<0||@@[index>=m_size](2))
{
@@[throw](2) IndexError();
}
return m_ptr[index];
}

int main()
{
ARRAY a(50);
int i;
cin >> i;
@@[try](2)
{
for(int j=0;j a.at(i) = j;
}
catch(IndexError e)
{
return 0;
}
return 0;
}
```







答案:
第1空:

第2空:T&ARRAY

第3空:index>=m_size

第4空:throw

第5空:try

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。