Search Contact information
University of Cambridge Home Department of Engineering
University of Cambridge >  Engineering Department >  computing help >  Languages >  C++

C++ for C programmers

Introduction

First there was B. Then there was C, which attained unofficial standardisation when Kernighan and Ritchie's 1st book came out. While C++ was being developed, C developed too, borrowing ideas for C++ to become "ANSI C" (or C89). C++ became official in 1997, care being taken to at least include all the C keywords in it. In September 1999 a new C codenamed C9X was ratified, introducing some keywords that C++ doesn't have.

Are you going to learn the latest C or move on to C++? Or maybe try java??

Some people say that C programmers might be best advised to start writing C++ in "the C++ way" right from the start but Stroustrup's not against a gradual transition, initially using C++ as if it were just "a better version of C". C++ doesn't force you to work in a particular way. It supports 3 main methodologies: procedural (like C), Object-orientated, and Generic (as with the Standard Library algorithms).

Procedural programming

Some small-scale changes do not require a lot of work.

Object-orientated programming

Some often mentioned advantages of object-oriented programming are: faster development, increased quality, easier maintenance, understandability and enhanced modifiability. Implementation details are hidden and interfaces provide precise and detailed instructions for the use of objects. Furthermore, an object-oriented approach is in many cases more natural and appeals more to human cognition than other methodologies.

Some important object-oriented concepts are

C supports some of these concepts to an extent, but becomes unwieldy, especially when C's lack of operator redefinition means that new types of objects can only be "added together" by calling functions.

Generic programming

The Standard Library contains lots of routines to deal with common data structures - sets, lists, vectors, etc. The same routine name can be used on different types of objects. See the Standard Template Library talk for examples.

C habits to give up

C++ is a flexible language. You can write C++ that a C compiler could compile (though behaviour might be different). You can even write in a style that isn't too distant from Fortran 77. But if you're a C programmer who wants to make the most of modern C++, the following points are worth bearing in mind

References

© Cambridge University Engineering Dept
Information provided by Tim Love (tpl)
Last updated: February 2000