C++

modified on 21 May 2010 at 20:41 - 1,094 views

From RoboWiki

Jump to: navigation, search

C++ is an Object Oriented programming language extended from C developed in 1979 by Bjarne Stroustrup. Object oriented programming is a paradigm that focuses on objects, or instances, of pre-defined data structures. This approach enables information hiding, better abstraction, encapsulation, modularity, better code reuse, polymorphism, and inheritance.

There have been other attempts to extend the C programming language with the object oriented paradigm, most notably Objective-C. The future of C++, and the C-like programming language family, seems to be moving towards in-language multi-threading. C++0x is the currently planned update.

Contents

[edit] Club Uses

The club uses this language on several platforms:

  • The Arduino supports pseudo-standard C++, and adds functions such as analogRead() that make working with it very simple.
  • Player/Stage is written in C and has a C++ interface.
  • C++ is designed to keep modularity and promote code reuse.

[edit] Getting Started

To use C++ as a programming language, you first have to install a compiler and development environment on your computer. Most of the Windows computers on campus include a development environment, Microsoft's Visual Studio. For personal use, however, Visual Studio can be prohibitively expensive. Fortunately, there are many free options to get a full-featured C++ compiler and development environment on your own computer.

[edit] Windows

[edit] Mac OSX

The gcc and g++ compilers are included with your computer, along with the pico and vim text editors, allowing you to do command line writing and compilation when needed. However, you can also use several IDE's that are cross-platform:

However, the standard IDE included with OSX is XCode, which is already installed on any OSX computer.

[edit] Linux

The gcc and g++ compilers are normally included in your distribution, along with the vi, emacs, or nano/pico text editors. If not, you can install them using your package managers: - For Red Hat:

sudo yum install gcc g++

- Ubuntu:

sudo apt-get install gcc g++

- Arch Linux:

sudo pacman -S gcc g++

Additionally, Eclipse and Netbeans are usually available from your package managers, allowing for non-command line programming. I.E.:

sudo apt-get install netbeans

[edit] Resources

Sams Teach Yourself C++ in 21 Days

The club recommends checking out the book from the engineering library "SAMS Teach Yourself C++ in 21 Days". There is an online version available here.

As with each programming language, there are several key features to keep in mind if you choose to develop with C++:

  1. Attempt to abstract code as much as possible, a goal of Object-Oriented Design
  2. When using dynamic allocation (with the new operator or malloc function) remember to always release (with the delete operator or free function) data
  3. Understand addressing and use pointers intelligently as they are a powerful, but sometimes dangerous, tool
  4. Never repeat code, simply create a class, function, or member
  5. Remember the concept of data-hiding, as well as the concept of a "black box" design