Panduan Pemrograman C++

Bahasa Pemrograman C++ Dan Visual C++ merupakan bahasa pemrograman pertengahan yang powerfull, namun sangat mudah dipelajari dan dipahami. Buku ini akan membantu Anda untuk menguasainya dengan mudah dan cepat. Materinya sengaja dikemas dalam tahap yang saling berhubungan. Juga disertai berbagai latihan untuk mempercepat pemahamannya. Dengan menguasai bahasa pemrograman C++, anda tidak akan kesulitan jika anda mempelajari bahasa pemrograman lainnya, seperti Web Programming with PHP, Pemrograman Java, Perograman C#, oleh karena itu mulailah belajar dari yang mudah, yaitu C++ Baca lebih lanjut

Iklan

The Syntax of C and C++ Function Pointers

2.1  Define a Function Pointer

Regarding their syntax, there are two different types of function pointers: On the one hand there are pointers to ordinary C functions or to static C++ member functions. On the other hand there are pointers to non-static C++ member functions. The basic difference is that all pointers to non-static member functions need a hidden argument: The this-pointer to an instance of the class. Always keep in mind: These two types of function pointers are incompatible with each other. Baca lebih lanjut

Introduction to Function Pointers

Function Pointers provide some extremely interesting, efficient and elegant programming techniques. You can use them to replace switch/if-statements, to realize your own late-binding or to implement callbacks. Unfortunately – probably due to their complicated syntax – they are treated quite stepmotherly in most computer books and documentations. If at all, they are addressed quite briefly and superficially. They are less error prone than normal pointers cause you will never allocate or deallocate memory with them. All you’ve got to do is to understand what they are and to learn their syntax. But keep in mind: Always ask yourself if you really need a function pointer. It’s nice to realize one’s own late-binding but to use the existing structures of C++ may make your code more readable and clear. One aspect in the case of late-binding is runtime: If you call a virtual function, your program has got to determine which one has got to be called. It does this using a V-Table containing all the possible functions. This costs some time each call and maybe you can save some time using function pointers instead of virtual functions. Maybe not … BTW: Modern compilers are very good! With my Borland Compiler the time I was able to save calling a virtual function which multiplies two floats was about 2 percent. Baca lebih lanjut