Ok is this solution correct??
Code:
#include <string.h>
#include <iostream.h>
class str
{
char *s;
public:
str(){}
~str()
{
delete []s;
}
str(str &p)
{
memcpy(this,&s,sizeof(s));
s=new char[strlen(p.s)+1];
}
void getdata(char*);
void putdata();
friend int xstrlen(str);
};
int xstrlen(str A)
{
int l=0;
while(*A.s)
{
l++;
A.s++;
}
return l;
}
void str::getdata(char* p)
{
s=new char[strlen(p)+1];
strcpy(s,p);
}
void str::putdata()
{
cout<<s<<endl;
}
int main(void)
{
str A;
A.getdata("string");
A.putdata();
xstrlen(A);
A.putdata();
return 0;
}
if yes! then now could you please explain me what am i doing when i call the xstrlen()??the control passes to copy constructor?but why??that i dont know?now please anybody explain me!what exactly is happening?