Class code error

Hello,

We have just started learning about classes and objects in my course and on one of the homeworks there is a small question that reads "This class definition (header file) has 5 errors, find these errors and complete the code"


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


Obviously the access specifier private is spelt incorrectly and is missing a colon. Also the integer variabe 'age' line does not finish with a ';' so there will be a compilation error. That's three, and the problem is I cannot see anymore. Correcting these leaves me with

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

This compiles fine in my IDE, which is perhaps not pedantic enough, so I am a little stuck for the final two errors. Constructor and destructor follow the correct rules, class ends with a ';' etc. Any advice in the right direction would be appreciated.
what kind of error do you talking about? Logic, link?

well, you need to implement human(); and ~human();. And better initialize the member variables.
Think about how you would create a new object of type human in main.
Topic archived. No new replies allowed.