Chapter 3

Moving to C + +

  • Converting from C to C++
  • New features of C++

  • Converting from C to C++
        If you've written a C program, you've probably already written your first C++ program ! With few excpection, C++ is a superset of C; that is, C++ supports almost all the features of the C language in addition to the many new features that it offers. Therefore, to get started with C++, you can simply compile your existing C programs, as well as the new programs you write, using the C++ compiler rather than the C compiler. You can then gradually begin adding to your code various features that are unique to C++


        To begin using the C++ compiler, you need only name your source file with the .cpp or .cxx extension, rather than the .c extension. There are, however several programming practices permitted in most versions of C that won't compile using the C++ compiler, or that will compile with C++ but with altered meanings. The following is a description of some of the most important C constructs that don't work with C++:


  • C++ has many more reserved keywords than C; these are words that you can't use as identifies in your programs. The following is a list of the reserved key - words used in Visual C++. This list includes the C Keywords, Plus many additional ones unique to  C++:
     auto               else                new              this
     bad-cast           enum                operator         throw
     bad_typeid         except              private          true
     bool               explicit            protected        try
     break              extern              public           type_info
     case               false               register         typedef
     catch              finally             reinterpret_     typeid




No comments:

Post a Comment