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

📄 fig05_28.cpp

📁 经典vc教程的例子程序
💻 CPP
字号:
// Fig. 5.28: fig05_28.cpp
// Demonstrating an array of pointers to functions
#include <iostream.h>
void function1( int );
void function2( int );
void function3( int );

int main()
{
   void (*f[ 3 ])( int ) = { function1, function2, function3 };
   int choice;

   cout << "Enter a number between 0 and 2, 3 to end: ";
   cin >> choice;

   while ( choice >= 0 && choice < 3 ) {
      (*f[ choice ])( choice );
      cout << "Enter a number between 0 and 2, 3 to end: ";
      cin >> choice;
   }

   cout << "Program execution completed." << endl;
   return 0;
}

void function1( int a )
{
   cout << "You entered " << a 
        << " so function1 was called\n\n";
}

void function2( int b )
{
   cout << "You entered " << b 
        << " so function2 was called\n\n";
}

void function3( int c )
{
   cout << "You entered " << c 
        << " so function3 was called\n\n";
}

⌨️ 快捷键说明

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