Hi All,
I am wondering why return type for an assignment opearator cant be a void or int?
Cant I write assignment operator for student class like this as we do nothing with returned value?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
Student
{
char name[20];
int marks;
public:
student(char*name,int marks)
{
\\some code
}
voidoperator=(student s) //lets assume proper copy constucotrs are written
forthisclass.
{
strcpy(name,s.name);
marks=s.marks
}
};
1 2 3 4 5 6 7 8 9 10 11
int main()
{
student s1("venkat",95);
student s2("Prasad,99);
s1=s2 //which also can be written as s1(s2)
//we do nothing with this return type.so why cant it be a void or int?
return 0;
}