Monday, December 12, 2011

[Cpp-Programming] Re: Inheritance and termination housekeeping

Hi!

> man object will cause program to crash because it does not use
> dynamic memory. To protect against this crash, I have used infamous
> IsBadStringPtr.  How can this program be structured to resolve this
> problem?

First and foremost I would recommend you use std::string, which does
exactly what you want, but safely!
have a look here: http://www.cplusplus.com/reference/string/string/

Second... if you have to use your own unsafe character buffers...
which you really should not do and you should regard this as an FYI
only:
Deleting NULL will always work. So set your fname and lname to NULL in
case you don't use any first+last names.

> CEmployee::CEmployee(int s)
> {
>         salary = s;
>
> }

change to
CEmployee::Cemployee(int s) : salery(s), fname(NULL), lname(NULL) { }

> CEmployee::~CEmployee(void)
> {
>         if(!IsBadStringPtr(fname, 25))
>         {
>                 delete [] fname;
>                 delete [] lname;
>         }}

change to
CEmployee::~CEmployee() {
delete[] fname; // it's ok if pointer is NULL
delete[] lname;
}

Greets,
BeyelerStudios

--
You received this message because you are subscribed to the Google Groups "C++ Programming" group.
To post to this group, send email to cpp-programming@googlegroups.com.
To unsubscribe from this group, send email to cpp-programming+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cpp-programming?hl=en.

0 Comments:

Post a Comment

<< Home