this program compilation succeeded but it doesnt work.
i guess it has something to do with the assignment operator or the copy constructor but i cant figure out what...
The problem in your code is in the constructor that takes a const char*. It allocates no memory for name to point to, but treats name as if it doesn't contain some arbitrary memory address.
The way you're using name it would make more sense for the class definition to be:
1 2 3 4
class employee{
char name[20] ;
// ...
};
Although, the following should probably be preferred:
first of all thanks for the help.
i added name=new name[20] to the constructor who gets the const char but now apparantly theres another problem with my assignment operator... can u tell what it is??
Other than the fact that you assign to the object that is supposed to be the source of the assignment, I don't see anything wrong with your assignment operator although the signature is unconventional.
A more conventional definition would look like the following: