P
pat
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 = 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!!!
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 = 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!!!