C++ for C Programmers

Categories:

Recommended

What is C++?

C++, at its essential core, is C with additional syntax to implement objects through the mechanism of classes. C++ upgrades the struct keyword with several new features;

The extensions to the struct keyword are significant enough that the keyword “class” has been added to the language to replace and/or augment “struct”. A class in C++ is the mechanism which facilitates the writing of Object Oriented programs.

Why you should learn C++.

  • Data hiding and Functional Implementation hiding via private data and public interface coding.
  • Skilled C programmers utilize techniques to implement data hiding. C++ formalizes and thus facilitates this practice.
  • Being able to define operators for your data structures without having to introduce new names into the programmers vocabulary.

In C, you define data structures with the struct keyword. The only operation defined for structs is =, a memberwise copy. If you want to add two instances of a struct, or compare two instances of a struct, you have to write a subroutine to perform the function and you have to advertise the name of the subroutine to the programmer that will be using it. This is silly. You already have the + and == operators to add and test for equivalency. Why can’t you use them for user defined types? In C++, you can define the data structure and what any of the standard operators ( + ++ – – = == * / … ) mean with respect to that data structure. Having operators for your data structures simplifies the programmer’s job. They don’t have to learn as many subroutine names to be able to use your data structure.

User defined variable initialization and deallocation code.

In C, when someone declares an instance of one of your data structures, the system executes code that is responsible for assigning initial values to that data structure. The user may specify initial values, however it is still system code that runs.

In C++, you have the option of writing what is known as constructor code. When someone declares an instance of one of your data structures, your constructor code can be executed. This can be extremely useful for error checking, data validation, user validation, auditing, billing, and tracking reasons.

  • Anything you can do in C you can do in C++.
  • Not everything you can do in C++ can be done in C.
  • Many new commercially available code libraries will only work with C++.

 

Category:

Attribution

JT Kalnay. C++ For Programmers. https://tfetimes.com/wp-content/uploads/2015/04/c-for-c-programmers.pdf

VP Flipbook Maker

Display your work as digital flipbook by VP Online Flipbook Maker! You can also create your own work with the tool. Try it now!