Function pointer type, function table, and interface theory notes (updated)

Source: Internet
Author: User

Function pointer definition:


Void (* point_fun) (const char * str );

Point_fun is first combined with * as a pointer and () as a function operator, so this pointer points to the Function

 

 

[Cpp]
# Include <stdio. h>
 
Void say_hello (const char * str );
Void (* point_say_hello) (const char * str); // point_say_hello is first combined with * as a pointer and () as a function operator, so this pointer points to the Function
 
Typedef void FUN (const char * str); // defines a FUN function type.
FUN say_typedef; // use the type definition defined above. FUN variables are equivalent to declaring a function.
FUN * point_say_typedef; // use the type definition defined above. The FUN type pointer is equivalent to defining a function pointer.
 
Void (* say_table [2]) (const char * str); // according to the sequence of operators, say_table is an array. The elements of an array are pointers to functions.
// Void (* say_table [2]) (const char * str) = {point_say_hello, point_say_typedef };
# Define say_interface (a) say_table [a] ("lang") // equivalent to the interface
 
Typedef void (* POINT_FUN) (const char * str); // defines the function pointer type of a POINT_FUN class.
POINT_FUN point_fun;
 
Void main (){
Printf ("lang start \ n ");
Point_say_hello = say_hello;
Point_say_hello ("langxw ");
 
Point_say_typedef = say_typedef;
Point_say_typedef ("langxw ");
 
Say_table [0] = point_say_hello;
Say_table [1] = point_say_typedef;
Say_interface (0 );
Say_interface (1 );

Point_fun = say_hello;
Point_fun ("point_fun ");
}
 
Void say_hello (const char * str ){
Printf ("hello % s \ n", str );
}
 
Void say_typedef (const char * str ){
Printf ("typedef % s \ n", str );
}

# Include <stdio. h>

Void say_hello (const char * str );
Void (* point_say_hello) (const char * str); // point_say_hello is first combined with * as a pointer and () as a function operator, so this pointer points to the Function

Typedef void FUN (const char * str); // defines a FUN function type.
FUN say_typedef; // use the type definition defined above. FUN variables are equivalent to declaring a function.
FUN * point_say_typedef; // use the type definition defined above. The FUN type pointer is equivalent to defining a function pointer.

Void (* say_table [2]) (const char * str); // according to the sequence of operators, say_table is an array. The elements of an array are pointers to functions.
// Void (* say_table [2]) (const char * str) = {point_say_hello, point_say_typedef };
# Define say_interface (a) say_table [a] ("lang") // equivalent to the interface

Typedef void (* POINT_FUN) (const char * str); // defines the function pointer type of a POINT_FUN class.
POINT_FUN point_fun;

Void main (){
Printf ("lang start \ n ");
Point_say_hello = say_hello;
Point_say_hello ("langxw ");

Point_say_typedef = say_typedef;
Point_say_typedef ("langxw ");

Say_table [0] = point_say_hello;
Say_table [1] = point_say_typedef;
Say_interface (0 );
Say_interface (1 );
 
Point_fun = say_hello;
Point_fun ("point_fun ");
}

Void say_hello (const char * str ){
Printf ("hello % s \ n", str );
}

Void say_typedef (const char * str ){
Printf ("typedef % s \ n", str );
}

 

 


End


 

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.