Hi,
this is the code to print s.
[code=cpp]main() {
sample s1(10,20,30);
char *s;
s="Hello"+s1;
}
friend char * operator +(char *s,sample &b) {
char *s1;
s1 = new char[50];
char *s2;
s2 = new char[10];
strcpy(s1,s);
strcat(s1,"Widt h");
sprintf(s2,"%g" ,b.width);
strcat(s1,s2);
strcat(s1,"Heig ht");
sprintf(s2,"%g" ,b.height);
strcat(s1,s2);
strcat(s1,"dept h");
sprintf(s2,"%g" ,b.depth);
strcat(s1,s2);
delete [] s2;
return s1;
delete []s1;
}
[/code]
Could anybody help me for optimization?
this is the code to print s.
[code=cpp]main() {
sample s1(10,20,30);
char *s;
s="Hello"+s1;
}
friend char * operator +(char *s,sample &b) {
char *s1;
s1 = new char[50];
char *s2;
s2 = new char[10];
strcpy(s1,s);
strcat(s1,"Widt h");
sprintf(s2,"%g" ,b.width);
strcat(s1,s2);
strcat(s1,"Heig ht");
sprintf(s2,"%g" ,b.height);
strcat(s1,s2);
strcat(s1,"dept h");
sprintf(s2,"%g" ,b.depth);
strcat(s1,s2);
delete [] s2;
return s1;
delete []s1;
}
[/code]
Could anybody help me for optimization?
Comment