📄 father.cpp
字号:
#include "stdafx.h"
#include "Father.h"
int Father::m_c=12;
Father::Father()
{
cout<<"the Father default init"<<endl;
m_a=8;
m_b=9;
}
Father::Father(Father &fa)
{
cout<<"the Fathercopy construct init"<<endl;
m_a=fa.m_a;
m_b=fa.m_b;
}
Father & Father::operator =(const Father &fa)
{
cout<<"the Father::function ="<<endl;
if(this==&fa)
{
return *this;
}
else
{
m_a=fa.m_a;
m_b=fa.m_b;
return *this;
}
}
Father::~Father()
{
}
int Father::GetA()
{
cout<<"(the Father GetA())";
return m_a;
}
void Father::SetA(int a)
{//子类重新写了m_a,但不管何时调用次函数,一定是this->m_a ,而成员没有多态,
//所以,如果子类调用了此函数,为子对象的Father::m_a 被赋值!
m_a=a;
}
int Father::GetB()
{
return m_b;
}
void Father::GetName()
{
cout<<"the father GetName!"<<endl;
}
void Father::func(int count)
{
cout<<"father func(int count)"<<endl;
}
void Father::func(char *p)
{
cout<<"father func(char *p)"<<endl;
return;
}
void Father::test1()
{
this->GetName();//(this->可以不写)!,在此埋下多态的伏笔!this 指的是调用函数的对象的地址,并且
//在Father::的成员函数中,当然是Father父亲类型!所以其实在所有的成员函数中调用virtual函数时,
//都是埋下多态的伏笔!
}
void Father::test2(Father &fa)
{
fa.GetName();//在此埋下多态的伏笔!
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -