Need help with destructor and pointers

Feb 22, 2016 at 3:51am
I got my program to initially work, but I realized I was supposed to add a destructor to my Employee class. So I went online to watch some tutorials and learn about destructors and realized I need pointers in which I didn't have initially. Here is my program, I can't seem to get my pointers to work now when i'm going back to add them for the destructor to work. Any help or advice would be appreciated.
Last edited on Feb 22, 2016 at 4:29pm
Feb 22, 2016 at 4:00am
Why are you trying to use pointers to strings in your class?

By the way you can't delete what you didn't new.

Feb 22, 2016 at 4:02am
To be honest I didnt realize it was still string, thats how I had it before trying to add pointers. I'll go back and fix it now. Thanks!
Feb 22, 2016 at 4:04am
I'll go back and fix it now.

I hope you mean you're going to remove all those silly pointers.
Feb 22, 2016 at 4:08am
I went back and posted my original code I had before adding all the pointers, any suggestions on how I would add a destructor to my employee class?
Feb 22, 2016 at 4:15am
You don't appear to need a destructor, the default compiler supplied constructor should work just fine since you no longer have any pointers in your class.

But you really should be using constructor initialization lists instead of the assignment in the body of the constructor.

http://en.cppreference.com/w/cpp/language/initializer_list


You also seem to be missing several required header file inclusions and using the "using namespace std; " clause in the global scope of a header is a very very bad practice.
Last edited on Feb 22, 2016 at 4:16am
Feb 22, 2016 at 4:38am
Thanks for the help, I'll read what you posted. Also out of curiosity why is it bad practice?
Feb 22, 2016 at 2:43pm
Because any file that happens to include this file will then be using this directive, thus causing name clashes that would be hard to diagnose.
Topic archived. No new replies allowed.