In this class,
line 3 "char * pName" and last line "char * name"
pName and name are pointers or strings?
I think they are pointers but if they are pointers how can we do
strlen(pName) and strcpy(name,pName) in the code?
Thanks
class student
{
public:
student(char * pName="no name",int ssId=0)
{
id=ssId;
name=new char[strlen(pName)+1];
strcpy(name,pName);
cout < <"construct new student " < <pName < <endl;
}
void copy(student & s)
{
if(this==&s)
{
cout < <"wrong" < <endl;
return;
}
else
{
name=new char[strlen(s.name)+1];
strcpy(name,s.name);
id=s.id;
cout < <"successful" < <endl;
}
}
void disp()
{
cout < <"Name:" < <name < <" Id:" < <id < <endl;
}
~student()
{
cout < <"Destruct " < <name < <endl;
delete name;
}
private:
int id;
char * name;
};