Jump to content

C++

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Pizza Puzzle (talk | contribs) at 10:04, 14 May 2003. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

C++ (pronounced "see plus plus") is an multi-paradigm programming language, which supports object-oriented programming; developed, during the 1980s, by Bjarne Stroustrup of Bell Labs. C++ is derived from C. C++ was standardized in 1998 (ISO/IEC 14882-1998). Along with it's object-oriented design, C++ is distinguished from C with its support for generic programming and template metaprogramming; via alias types, in-line expansion, templates, and //-commenting. In-line expansion and //-commenting were added to C, as part of the C99 update.

History of C++

Stroustrup began work on the language in 1979, inspired by Simula67, and the language was first used, by AT&T, in August 1983. The original compiler was Cfront. The first commercial release was in October 1985.

History of the Name "C++"

While most C is valid C++, C is not a subset of C++; although, the names do indicate a distinct relationship. This name is credited to Rick Mascitti (mid-1983) and was first used in December '83. Earlier, during the research period, the developing language had been referred to as "C with Classes". The name stems from C's "++" operator (which increments the value of a variable) and a common naming convention of using "+" to indicate an enhanced computer program, for example: "Wikipedia+". According to Stroustrup: "the name signifies the evolutionary nature of the changes from C". C+ was earlier used as the name for an unrelated program.

Some C-programmers have noted:

  • if x=3 and y=x++, then x=4 and y=3;however, if y=++x, then y=4 and x=4.

Following such reasoning, a more proper name for C++ might actually be ++C. However, other C-programmers do use the expression "c++" to increment the variable "c".

Ownership of C++

Nobody owns C++. Stroustrup and AT&T are not paid royalties for the usage of C++.

"Hello Wikipedia!" Program

The below code can be compiled into a program which outputs a text message. See also: Hello world program

#include <iostream> // The <iostream> header is needed for std::cout
 
int main() // Beginning of main() routine
{          // { ... } is used to include blocks of code
    std::cout << "Hello, Wikipedia!\n"; // Outputs the text enclosed with "" 
}

Note that older (non-standard) C++ compilers, such as Borland C++ 5.02, usually require <iostream.h> instead of the standard <iostream>, and cout instead of std::cout.

Class definition

#include <string>
using std::string;

class InetMessage
{
  string m_subject, m_to, m_from;

public:
  InetMessage (const string& subject,
	       const string& to,
	       const string& from);
  string subject () const;
  string to () const;
  string from () const;
};