Errors in class definition

Hi everyone, apparently there are 5 errors in the class definition within a header file shown below. So far I have only been able to identify three errors:

- Typo in 'privete'
- Missing ':' after 'privete'
- Missing semi-colon after 'int doornumber'

I think the last two errors have something to do with the line 'char surname[2];' But I can't figure it out, any help is much appreciated! Thank you!

1
2
3
4
5
6
7
8
9
class person
{
   public :
      person();
      ~person();
   privete
      char surname[2];
      int doornumber
};
the messages already tell the errors :

1
2
3
4
5
6
7
8
9
class person
{
   public :
      person();
      ~person();
   private :
      char surname[2];
      int doornumber;
};
I think the last two errors have something to do with the line 'char surname[2];'

Well, there's one I can think of regarding that definition.

Hint: It's not a problem with the syntax - which is legal - but to do with whether the definition as it stands is suitable for the data that you'd expect to be stored in it.

The only other thing I can think of that might be classed as an error is to do with the declaration of the destructor. Although it's not really an error, as such, unless person is intended to be used as a base class.
@shadow fiend - Yes, but that only identifies three errors, not five.

@MikeyBoy - Yeah, I mean I can only think of 'wishy washy', 'semantic' errors, such as the character array being too small to be able to store a surname and perhaps using an unsigned integer since age is only ever positive.

What do you mean by declaration of the destructor? Haven't seen this in my notes? I think one of the key things is that we can't assume there is code 'missing', I did that in the past and was quickly reprimanded since this constitutes a 'code snippet' so there may be more code somewhere else.
what are the exact error messages the compiler says ?

-Are you sure you have implemented the constructor and destructor and not just forward declare those ?
such as the character array being too small to be able to store a surname

Yeah, that's the one I was thinking of. I wouldn't say it was "wishy-washy" - any attempt to store a surname more than 2 characters long will result in undefined behaviour, which could mean data corruption or a crash.

Believe me, as a programmer, errors that your compiler tells you about are the easy ones to find and fix. It's the ones that compile just fine that are the ones you really need to learn how to find and fix.

As for using an unsigned int rather than an int - I think you'd have to be pretty pedantic to call that an "error" ;)

As for the destructor - have you covered inheritance and polymorphism yet?
One thing that is sort of not ok is that local variables are useless during object's life time. There is no way to access them since they are private and even (seemingly) no way to set them, as constructor do not take arguments. There is also no existing function that could make use of them except of destructor.

On the other hand the constructor might use some elaborate computations to set them, and then destructor might interact with some external objects using these values, but nothing can happen during actual lifetime.
@shadow fiend - I haven't put it through my IDE, it's just a code snippet with 5 errors in it. It's a question from my C++ Problem Sheet which seems to be on classes on the whole.

@MikeyBoy - I agree that one isn't wishy washy, but my integer one was, it's all I can come up with? We have covered inheritance and polymorphism, I'm not an expert on it by any means though and I'm struggling to clearly see what the problem with the constructor and destructor is, I suppose the fact it takes no arguments would mean there'd be no way to access your private variables maybe?

@JockX - Is what you're saying sort of the same as what I said above in response to MikeyBoy?

All in all, I'm still struggling to find a legitimate 5th error!
Sorry for the double post, but I think I have one. So since the constructor takes no arguments, there is no way to access the private variables within this class - this bit of code effectively does nothing? To remedy this one could change the access specifier of the data members to public (bad practice), or overload the constructor, or redefine the constructor to take some parameters, or declare some functions through which one can access the data members.

Is that one? I think it seems totally legit?
Topic archived. No new replies allowed.