⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 insect.cpp

📁 VC++串口通信设。本书详细说明讲解了在VC++环境下编写串口通信得过程。值得一看
💻 CPP
字号:
#include <iostream>
#include <string>

using namespace std ;

class Insect
{
public:

   // Public methods
   virtual bool CanFly() const;
};

bool Insect::CanFly() const
{
   return false;
}


class Dragonfly : public Insect
{
public:

   // Overriden method
   bool CanFly() const;
};

bool Dragonfly::CanFly() const
{
   return true;
}


class Beetle : public Insect
{ };


class Ant : public Insect
{ };


void main()
{
   Beetle    ABeetle;
   Ant       AnAnt;
   Dragonfly ADragonFly;

   // Fill up our array of bug pointers
   Insect*   InsectArray[] = { &AnAnt, &ADragonFly, &ABeetle };

   // Ask each insect if it can fly
   for (int loop = 0; loop < 3; loop++) 
   {
      cout << "Insect #" << loop+1;

      // Here's the polymorphic method call
      if (InsectArray[loop]->CanFly() == true)
         cout << " can ";
      else 
         cout << " cannot ";

      cout << "fly.\n";
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -