?? 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 + -