"Thinkinginc++" 18, pointer to function array

Source: Internet
Author: User
/*** function: pointer to function array * Time: August 14, 2014 07:24:46* Author: cutter_point*/#include <iostream> #include <cstdlib>using namespace std;//here n is the function name, and DF (n) represents the following N function, n can be changed to # define DF (n) void N () {cout<< "function" #N "is called" << Endl;} DF (a);D f (b);D F (c);D F (d);D f (e);D f (f);D F (g);  This is equivalent to 7 function void (*func_table[]) () ={a,b,c,d,e,f,g};int main () {    while (1)    {        cout<< "enter two characters in ' a ' to ' G ' Between, Q is Exit "<<endl;        Char C1, C2, C3;        cin>>c1>>c2;        c3= ' Q ';        Determine if the program should exit        if (c1 = = ' Q ') break            ;        if (c1< ' a ' | | | c1> ' g ')            continue;        (*func_table[c1-' a ']) ();        cout<< "#c1:" <<c1<< "\T#C2:" <<c2<<endl;    }    System ("pause");    return 0;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.