クラス継承のthisポインタ
762 ワード
次の列に結合します.
// , , this
#include "stdafx.h"
#include "cstdio"
#include "iostream"
using namespace std;
class CAnimal
{
private:
int m_nType;
public:
void SetType(int type) // void SetType(int type,(CAnimal*)this)
{
m_nType = type; // this->m_nType = type
cout << "Type is " << m_nType << endl;
}
};
class Cbird : public CAnimal
{
public:
void Cry()
{
}
};
int main(int argc, char* argv[])
{
Cbird bird1,bird2;
bird1.SetType(1); // Cbird::SetType(1,(Cbird*)&bird1); CAnimal::SetType(1,(Cbird*)&bird1);
bird2.SetType(2); // Cbird::SetType(2,(Cbird*)&bird2); CAnimal::SetType(2,(Cbird*)&bird2);
return 0;
}