Errors in code snippet

Hello, I have the following homework problem to answer. We have just started looking at classes.


This class definition (header file) has 5 errors. Identify them bearing in mind that not all errors will cause a compiler or runtime failure, some may just be bad design.

1
2
3
4
5
6
7
8
9
class human
{
public :
	human();
	~human();
privete
	char name[2];
	int age
};


That is exactly how the code is presented in the question. The first three obvious errors are the spelling of privete should be private, it should be followed by a colon, ie private: and the variable int age should end with a semi colon as such int age;. I think a fourth error might be that the normal convention of giving the class a name which begins with an upper case letter has not been followed, ie class Human instead of class human, could that be considered bad design? I am struggling to find a fifth error, I hope someone can point me in the right direction.

Thanks
the actual question states that they are classing bad design as an 'error'. So yea, I guess lower case class name could count. although I see nothing wrong with doing that to be honest.

but then it becomes quite subjective. for example, should you have your private stuff declared before your public stuff? that kinda thing. who knows :)
Last edited on
include guards?
I think a fourth error might be that the normal convention of giving the class a name which begins with an upper case letter has not been followed

That's purely a matter of style and not an error. Your instructor maybe a stickler for style and consider that an error, especially if he has been teaching you that way.

I would say an error is allocating only 2 characters for name. That allows 1 character plus a terminating null. Not long enough to store a meaningful name.

Some other things to consider:
- No explicit constructor that initializes name and age.
- No useful methods in the class. i.e. You can construct an instance of the class using the default constructor, but there is nothing you can do with the instance.

Thank you, these suggestions were helpful.
Topic archived. No new replies allowed.