13,825
社区成员
发帖
与我相关
我的任务
分享
class Array
{
Array& operator=(.....);
};
Array& Array::operator=(.....)
{
}
#include <string>
using namespace std;
class Student
{
private:
string name;
int age;
public:
Student();
Student(string name, int age);
~Student();
Student& operator=(const Student& rhs);
void display() const;
};
Student.cpp
#include "Student.h"
#include <iostream>
using namespace std;
Student::Student()
{
}
Student::Student(string name, int age)
{
this->name = name;
this->age = age;
}
Student::~Student()
{
}
void Student::display() const
{
cout << name << "\t" << age << endl;;
}
Student& Student::operator=(const Student& rhs)
{
name = rhs.name + "的克隆";
age = rhs.age;
return *this;
}
main.cpp
#include "Student.h"
int _tmain(int argc, _TCHAR* argv[])
{
Student a("xiaomin", 20);
Student b, c;
c = b = a;
a.display();
b.display();
c.display();
return 0;
}