The key thing missing is the name of the class of which the function was a member. What is the type of a pointer to member function? We already know what the type of add would be if it wasn’t a member function: double (*)( int, float ) Ignore the fact that add makes absolutely no sense as a member function (very few of these examples make any sense outside of a narrow context). Pointer to member function class TestClass2 Let’s not get too confident though, overloads are going to return to trouble us later. The function selected is the one whose type is identical to the function type of the target type required in the context. Section 13.4 of the C++11 standard states: Overloaded functions double add( int i, float f )Įven overloaded functions work just as we’d expect. Nothing tricky about putting functions into a namespace, or a class acting as a namespace. Let’s dispense with the easy options quickly then get on to the more interesting possibilities.Ī function in a namespace namespace arithmeticĭouble (*pFn)( int, float ) = arithmetic::add Ī static function in a class class TestClassĭouble (*pFn)( int, float ) = TestClass::add C++ also gives us some other ways of creating functions though. Since C++ is mostly a superset of C we can do those things in C++ as well. In part 1 we looked at various things we can do with functions in C.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |