Let we have a class class String private char buf 25 Write code-00988
This subjective question is related to the book/course vu cs605 Software EngineeringII. It can also be found in vu cs605 Mid Term Solved Past Paper No. 1.
Question 1: Let we have a class,
class String {
private:
char buf[25];
};
Write code for assignment (=) operator function which assign one String object to other object. Your code should also avoid self assignment
int length ;
length = other.length();
delete buf;
buf = new char [length + 1];
strcpy( buf, other.buf );
}Page. No. 15/15
class String {
private:
char buf[25];
};
Write code for assignment (=) operator function which assign one String object to other object. Your code should also avoid self assignment
Answer:
void String::operator = ( const String &other ) { int length ;
length = other.length();
delete buf;
buf = new char [length + 1];
strcpy( buf, other.buf );
}Page. No. 15/15