C++ (programming language)

From Bauman National Library
This page was last modified on 8 June 2016, at 21:15.
C++
Paradigm Multi-paradigm: procedural, functional, object-oriented, generic[1]
Designed by Bjarne Stroustrup
Stable release ISO/IEC 14882:2014 / 15 December 2014; 5 years ago (2014-12-15)
Typing discipline Static, nominative, partially inferred
Website isocpp.org
Major implementations
Template:Nowraplinks
Influenced by
C, Simula, ALGOL 68, Ada, CLU, ML
Influenced
Ada 95, C99, C#,[2] Chapel,[3] D, Java, Lua, Rust, Python, Perl, PHP

C++ - compiled, statically typed general-purpose programming language.

It supports such paradigms as procedural programming, object-oriented programming, generic programming, provides modularity, separate compilation, exception handling, data abstraction, object (class) type declaration, virtual functions. Standard library includes commonly used containers and algorithms. C++ combines properties of high-level and low-level programming languages. In comparsion to its precursor - C language most attention is paid to object-oriented programming and generic programming.

C++, which one of the most popular programming language, is widely used for software development. Its apllication area includes operating systems development, variety application programmes, device drivers, applications for embedded systems, applications for high-performance servers and entertaining applications.

History

Development

C++ programming language was created in eary 1980. Its developer collaborator of Bell Laboratories firm - Bjarne Stroustrup. He invented several improvement for C programming langugage for own needs, i. e. originally C++ wasn't plan to be created. Earliest versions of C++ programming language known as C with classes began appears since 1980. C programming language, which is a basic language of UNIX system, is high-performance, multifunctional, portable. Stroustrup added the opportunity to work with classes and objects. Thereby he engendered premise new language based on C. C++ syntax was based on C syntax besause Bjarne Stroustrup wanted to save compatibility with C programming language.

Evolution

First edition of "C++ programming language" was published in 1985. It provides first C++ language description what was important because official standard was absent.

In 1989, C++ 2.0 was released, followed by the updated second edition of The C++ Programming Language in 1991. New features in 2.0 included multiple inheritance, abstract classes, static member functions, const member functions, and protected members.

"In 1990, The Annotated C++ Reference Manual was published. This work became the basis for the future standard. Later feature additions included templates, exceptions, namespaces, new casts, and a boolean type.

The standard ISO/IEC 14882:1998 know as C++89 was publicshed in 1998. It was developed by International Organization for Standardization. The standard was consist of two parts: language basics and standars language library, which included Standard Template Library (STL) and modified version of C standard library.

Standars ISO/IEC 14882:2003 was publiched in 2003. In this standars bugs of previous versions were fixed.

Library Technical Report 1 was published in 2005. This report describes expansions of standard library, which must be included in next version of C++ language.

The work on updating the previous standard was conducted since 2009.

After the 2.0 update, C++ evolved relatively slowly until, in 2011, the C++11 standard was released, adding numerous new features, enlarging the standard library further, and providing more facilities to C++ programmers. After a minor C++14 update, released in December 2014, various new additions are planned for 2017.

Etymology

C++ name was was coined by Rick Mascitti. The name signifies the evolutionary nature of the changes from C. 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. This language didn't get D name because is's appear as C expension.

Language overview

Non object-oriented features

Types:

  • Character: char, wchar_t (char16_t и char32_t, in C++11 standard)
  • Sign integer: signed char, short int, int, long int (long long int, in C++11 standard)
  • Unsigned integer: unsigned char, unsigned short int, unsigned int, unsigned long int(и unsigned long long int, in C++11 standard)
  • Float: float, double, long double
  • Logical: bool

Сomparison operations return bool type. Expressions in brackets are converted to bool type.

Functions can get parametrs by reference. Fuctions can return result by reference. References are similar to pointers with following features: reference must be initialized before using; referce always points on the same address; reference directly denote the object or the function to which it points, handling to object or funcrion by reference require dereference the pointer.

New features:

  • inline fuctions
  • volatile descriptor
  • namespaces
  • templates
  • Operators new, new[], delete и delete[]

Object-oriented features

C adds to the C ++ object-oriented features. It introduces classes, which provide the three most important properties of OOP: encapsulation, inheritance, and polymorphism.

Class methods - functions that can be applied to instances of the class. Roughly speaking method - the function declared within a class, and designed to work with its objects. The methods are declared in the class body. Can be described the same place, but they can outside of class (within the class in this case is sufficient to provide a prototype method, and outside of class to determine the method of placing before its name - the name of the class and the operator ::). Methods and fields wich are included in the class called members of the class. Wherein methods are often called as member functions.

Inheritance

In C ++, inheritance of a class inherits from another class implementation and drived-class can add own fileds and fuctions or overwrite the base class functions. Multiple inheritance is allowed.

Constructor of derived class call constructor of base the class and then constructors of non-static data members, which are instances of classes. Destructor works шт in reverse order.

Inheritance can be a public, protected and private.

Polymorphism

The purpose of polymorphism, in relation to the object-oriented programming, is the use of a single name for the tasks are common to a class action. Implementation of each individual action will be determined by the data type.

The advantage of polymorphism is that it helps to reduce the complexity of programs, allowing to use the same interface to set a single action class. The choice of a particular action entrusted to the compiler. Polymorphism can be also applied to the operators.

Encapsulation

The main way to organize information in a C ++ are classes. Unlike the structure of C language, which can consist only of the fields and sub-types, C ++ class can consist of fields, nested types and member functions. Encapsulation is implemented in C++ by specifying the level of access to members of the class: public, protected and private.

Standars library

In the C++ programming language standard library term means a collection of classes and functions written in the base language.

It includes vectors, lists, maps, algorithms (find, for_each, binary_search, random_shuffle, etc.), sets, queues, stacks, arrays, tuples, input/output facilities (iostream, for reading from and writing to the console and files), smart pointers for automatic memory management, regular expression support, multi-threading library, atomics support (allowing a variable to be read or written to be at most one thread at a time without any external synchronisation), time utilities (measurement, getting current time, etc.), a system for converting error reporting that doesn't use C++ exceptions into C++ exceptions, a random number generator and a slightly modified version of the C standard library (to make it comply with the C++ type system).

A large part of the C++ library is based on the Standard Template Library (STL). Useful tools provided by the STL include containers as the collections of objects (such as vectors and lists), iterators that provide array-like access to containers, and algorithms that perform operations such as searching and sorting.

Differences from C

New features:

  • support for object-oriented programming
  • support for generic programming via templates
  • additional data types
  • exeptions
  • namespaces
  • inline fuctions
  • operators overloading
  • functions overloading
  • references
  • additions to the standard library

C++ doesn't allow:

  • call the function main() within the program, while in C this action is legitimate.
  • implicit casting between unrelated pointer types
  • using functions before declaration

Advantages and disadvantages

C ++ - language emerging evolutionary. Each element was taken from other languages separately and independently from the other elements (none of these in the history of its development was not a novelty in Computer Science), what made language extremely difficult with a lot of duplicated and mutually contradictory elements.

Critics C ++ do not oppose him any particular language, but on the contrary, argue that for every case of application C ++ is always an alternative tool allowing to solve the same problem more effectively and efficiently. Proponents of C++ suppose that it's incorrect co comapre various aspects of C++ with completely different laguages because a common set of tools and features C++ significantly wider than in most languages, which compares. Huge amount of possibilities is a excuse of the imperfections of each individual opportunity.

Advantages:

  • High compatibility with the C language
  • High-performance
  • Supporting for various programming styles: structured, object-oriented, generic programming, functional programming, generative metaprogramming
  • Automatic destructors call
  • Pperators overloading
  • Templates (allowed to build generalized containers and algorithms for different types of data)
  • Expandable language support paradigms
  • Availability

Disadvantages:

  • Inconvenient language syntax
  • Absence of many important features
  • Contains dangerous possibilities
  • Programmer productivity is low
  • The cumbersome syntax
  • Difficult inheritance
  • Memory monitoring requiring

Examples

Печать "Hello, World!":

#include <iostream>

int main()
{
    std::cout << "Hello, world!\n";
    return 0;
}

Сортировка пузырьком:

#include<stdio.h>
#define N 1000
int main()
{
	int n, i, j;
	int a[N];

	scanf(%d, &amp;n);

	for(i = 0 ; i < n; i++)
	{
		scanf(%d, &amp;a[i]);
	}

	for(i = 0 ; i < n ; i++)
	{
		for(j = 0 ; j < n  i  1 ; j++)
		{
			if(a[j] > a[j+1])
			{
				int tmp = a[j]; a[j] = a[j+1] ; a[j+1] = tmp;
			}
		}
	}
}

Further reading

External links

  1. The C++ Standards Committee
  2. C++11
  3. C++ Basics of programming
    1. Template:Cite book
    2. Template:Cite journal
    3. "Chapel spec (Acknowledgements)" (PDF). Cray Inc. 2015-10-01. Retrieved 2016-01-14.