131: Data Types: Function Pointers Part 2.

You may not always need to work with this data type but that doesn’t mean you can ignore it. If you don’t at least know the basics, then you’ll get lost in code that uses function pointers. You can listen to the episode for the full description. I’ll use this space to show you how to declare and work with a class member function pointer.// Class method declaration. class Number { public: Number () : mValue(0) { } virtual int addValue (int value); private: int mValue; }; // Class method pointer type declaration compatible with the addValue method. using AddPointer = int (Number::*)(int); // Class method pointer variable declaration and assignment. AddPointer functionPtr = &Number::addValue; // Declaring an instance of the Number class and a pointer to that instance. Number numberInstance; Number * numberInstancePointer = &numberInstance; // Calling the addValue method directly and then through the pointer. int result = numberInstance.addValue(5); result = numberInstancePointer->addValue(5); // Calling the addValue method using the function pointer through both an instance and a pointer to an instance. result = numberInstance.*functionPtr(5); result = numberInstancePointer->*functionPtr(5);

Om Podcasten

Take Up Code is a podcast that explains computer programming topics through fun and engaging examples that you can relate to. The guided format allows you to gain valuable understanding of topics that will reinforce your studies, allow you to train new skills that you can apply on your job, and change your thinking about what it takes to become a professional programmer. The episodes are as short as possible so you can squeeze them into your daily routine.