Even after programming in C for decades, I occasionally still discover things about it. While typedef
s of pointer to function are common, I just discovered that you can have typedef
s of function by stumbling across their use in some open-source project (though I don't recall which one). That is instead of the common:
typedef void (*PF)(int);
PF pf; // pf is a pointer to function
you can instead do:
typedef void F(int);
F *pf; // pf is (also) a pointer to function
One advantage the latter is that it makes it more obvious that you're dealing with pointers.
I suppose the reason for not knowing about typedef
s of function is that there are no such examples in either the first or second editions of The C Programming Language (though there are examples of typedef
s of pointer to function). There is, however, an example in the C99 standard §6.7.7.4:
After
typedef int MILES, KLICKSP();
the constructions
extern KLICKSP *metricp;
are all valid declarations. The type of ...
metricp
is ‘‘pointer to function with no parameter specification returning int’’ ....
Top comments (5)
overriding can help me redefine the definition of the base class function
then why we required the virtual keyword because it also help me redefine the function
then plz help me to solve the contraversy
No. This post isn't the place for that.
Then how and where
Here comes to mind.
can you explain me what is overriding and what is difference b/w overriding and virtual function
and also what is the use of the virtual function
Some comments have been hidden by the post's author - find out more