C++运算符重载的方法详细解析

C++运算符重载的方法详细解析
文章图片



C++运算符重载的方法详细解析
文章图片



#include
using namespace std;
class Person
{
public:
Person()
{
cout << "Person()" << endl;
}
Person(char a)
【C++运算符重载的方法详细解析】{
sexy=a;
cout << "Person(char a)" << endl;
}
void info()
{
cout << "sexy=" << sexy << endl;
}
private:
char sexy;
};
class Student:public Person
{
public:
Student()
{
cout << "Student()" << endl;
}
Student(string a,int b,char c):Person(c)
{
name =a;
age =b;
}
void info()
{
cout << "name=" << name << "\n" << "age=" << age << endl;
}
private:
string name;
int age;
};
int main()
{
Student stu("zhangsan",18,'f');
stu.info();
stu.Person::info();
//注意格式,不是Person::stu.info(); 否则会提示stu is not a member of ‘Person’

return 0;
}


C++运算符重载的方法详细解析
文章图片

    推荐阅读