80 likes | 207 Vues
The shift from C to C++ offers numerous advantages, particularly through support for object-oriented programming. This transition allows for the hiding of implementation details, code reuse via class templates, and the extension of class functionality through operator overloading. Key approaches include leveraging function prototyping to minimize errors, enhancing I/O safety, and optimizing performance with inline functions. While the change necessitates effort and thoughtful design—such as defining fundamental object operations—embracing these changes can significantly enhance code structure and efficiency.
E N D
What do we know? • The sky is blue • Snow is cold
What do we know? • The sky is blue • Snow is cold • This girl is hot AND... • C++ supports object-oriented programming
What are the options? • Hide implementation details • Reuse class code • Reuse generic classes use a C++ class template and let the compiler do the work • Extend/Overload operators • Derive classes from base classes
What are the options? • Avoid errors through function prototyping • Add parameters without changing function calls • Using safer, simpler I/O • Improve performance with fast inline functions • Overload function names
Some remarks • Change involves effort Changes will be necessary!! • Massage C code into C++ extern “C” {...} • The hard part: designing objects ask what fundamental operations define each object • If it ain’t broke, don’t fix it!