當前位置:編程學習大全網 - 編程軟體 - c++想利用父類指針實現多態, 編程出錯跪求高手指點

c++想利用父類指針實現多態, 編程出錯跪求高手指點

#ifndef?BASE00_H

#define?BASE00_H

class?base00

{

public:

base00();

virtual?~base00();

virtual?void?GetPortCount(void)?=?0;

protected:

private:

};

class?base01?:?public?base00

{

public:

base01();

virtual?~base01();

virtual?void?GetPortCount(void);

protected:

private:

};

class?base02?:?public?base01

{

public:

base02();

virtual?~base02();

virtual?void?GetPortCount(void);

protected:

private:

};

#endif?//?BASE00_H

#include?<iostream>

#include?"base00.h"

using?namespace?std;

base00::base00()

{

//ctor

std::cout?<<?__func__?<<?std::endl;

}

base00::~base00()

{

//dtor

std::cout?<<?__func__?<<?std::endl;

}

base01::base01()

{

//ctor

std::cout?<<?__func__?<<?std::endl;

}

base01::~base01()

{

//dtor

std::cout?<<?__func__?<<?std::endl;

}

base02::base02()

{

//ctor

std::cout?<<?__func__?<<?std::endl;

}

base02::~base02()

{

//dtor

std::cout?<<?__func__?<<?std::endl;

}

void?base01::GetPortCount()

{

std::cout?<<?"base01::GetPortCount"?<<?std::endl;

}

void?base02::GetPortCount()

{

std::cout?<<?"base02::GetPortCount"?<<?std::endl;

}

int?main(int?argc,?char?**argv)

{

cout?<<?"Hello?world!"?<<?endl;

base00?*b1?=?new?base01;

base00?*b2?=?new?base02;

b1->GetPortCount();

b2->GetPortCount();

delete?b1;

delete?b2;

return?0;

}

  • 上一篇:手機android系統的yume_android_sdk文件夾是什麽
  • 下一篇:什麽是吸塑雕刻
  • copyright 2024編程學習大全網