在此代码中查找错误... [英] Finding errors in this code...

查看:60
本文介绍了在此代码中查找错误...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我在两天内参加了c ++考试,其中一个过去的

问题如下。


识别6此代码中的语法和2个可能的运行时错误:

class demo

{

private:

unsigned char len ,* dat;

public:

demo(unsigned char le = 5,unsigned char default):len(le)

{

dat = new char [len];

for(int i = 0; i< = le; i ++)

dat [i] =默认;

void~demo(void)

{

delete [] * dat;

}


};

class newdemo:public demo

{


private:

int * dat1;

public:

newdemo(void):demo(0,0)

{

* dat1 = 0;

返回0;

}


};

我很确定我有4但不确定它们是语法还是运行时

错误...


1 - 第5行,unsigned c har len,* dat;"应该是两个单独的

声明。

2 - 第16行,void~demo(void),不能有析构函数的返回类型。 />

3 - 第18行,删除[] * dat",不应该是*这里。

4 - 第32行,return 0;,构造函数不能有返回类型。

任何人都可以告诉我剩下的错误是什么原因我不知道是什么?b $ b没什么线索,有没有人知道上面是运行时还是语法


错误,如果有一种简单的方法可以区分两者。

任何帮助都会很棒,谢谢!!!

解决方案

pat写道:

大家好,我在两天内参加了c ++考试。 ..




FAQ涵盖了这个问题:

http://www.parashift.com/c++-faq-lit...t.html#faq- 5.2

如何让其他人为我做我的作业问题?


在发布之前检查常见问题是alw很好。


-

Phlip
http://c2.com/cgi/wiki?ZeekLand < - 不是博客!!!


< blockquote>苛刻,公平,我无法弄清楚其他四个错误

是什么,我想有人可能想要帮忙。如果你不想,

罚款。


顺便说一下,这不是一个家庭作业,这是一个过去的问题

我无法弄清楚的试卷。


苛刻,公平地说我无法解决什么问题其他4个错误是和

我认为有人知道可能想要帮忙。如果你不想要b $ b那么好。


顺便说一下,过去的考试试卷中的问题不是作业。

分配。这样做我不会得到任何分数。


Hi everyone, I''ve got an exam in c++ in two days and one of the past
questions is as follows.

Identify 6 syntax and 2 possible runtime errors in this code:
class demo
{
private:
unsigned char len, *dat;
public:
demo(unsigned char le = 5, unsigned char default) : len(le)
{
dat = new char[len];
for ( int i = 0 ; i <= le ; i++ )
dat[i] = default;
void ~demo(void)
{
delete [] *dat;
}

};
class newdemo : public demo
{

private:
int *dat1;
public:
newdemo(void) : demo(0, 0)
{
*dat1 = 0;
return 0;
}

};
I''m pretty sure I have 4 but am not sure if they are syntax or runtime
errors...

1 - line 5, "unsigned char len, *dat;" should be two seperate
declarations.
2 - line 16, "void ~demo(void)", can''t have return type for destructor.

3 - line 18, " delete [] * dat", shouldn''t be a * here.
4 - line 32, "return 0;", constructor can''t have return type.
Would anyone be able to tell me what the rest of the errors are cause i

haven''t a clue, and does anyone know if the above are runtime or syntax

errors and if there is an easy way to differentiate between the two.
Any help would be great, thanks!!!

解决方案

pat wrote:

Hi everyone, I''ve got an exam in c++ in two days and...



The FAQ covers this question:

http://www.parashift.com/c++-faq-lit...t.html#faq-5.2
"How do I get other people to do my homework problem for me?"

Checking the FAQ before posting is always good.

--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!


Harsh, in fairness, I couldn''t figure out what the other four errors
were and I thought someone might WANT to help. If you don''t want to,
fine.

By the way, it''s not a homework assignment, its a question from a past
exam paper that I couldn''t figure out.


Harsh, in fairness I couldn''t work out what the other 4 errors were and
I thought someone who knew might WANT to help. If you don''t want to
thats fine.

By the way its a question from a past exam paper not a homework
assignment. I won''t gain any marks from doing it.


这篇关于在此代码中查找错误...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆