Changes

1,370 bytes added ,  20:33, 27 May 2022
m
KS update 1.2
Line 2: Line 2:  
| name                  = C++
 
| name                  = C++
 
| logo                  = File:ISO C++ Logo.svg
 
| logo                  = File:ISO C++ Logo.svg
| paradigm              = [[Multi-paradigm programming language|Multi-paradigm]]:<ref name="stroustruptcpppl"/> [[procedural programming|procedural]], [[functional programming|functional]],  [[object-oriented programming|object-oriented]], [[generic programming|generic]]
+
| paradigm              = [[Multi-paradigm programming language|Multi-paradigm]]:<ref name="stroustruptcpppl" /> [[procedural programming|procedural]], [[functional programming|functional]],  [[object-oriented programming|object-oriented]], [[generic programming|generic]]
 
| year                  = 1983
 
| year                  = 1983
 
| designer              = [[Bjarne Stroustrup]]
 
| designer              = [[Bjarne Stroustrup]]
 
| developer              = Bjarne Stroustrup<br>[[Bell Labs]]<br>{{nobr|ISO/IEC JTC1/SC22/WG21}}
 
| developer              = Bjarne Stroustrup<br>[[Bell Labs]]<br>{{nobr|ISO/IEC JTC1/SC22/WG21}}
| latest_release_version = ISO/IEC 14882:2017
+
| latest_release_version = ISO/IEC 14882:2020
| latest_release_date    = {{Start date and age|2017|12|01|df=yes}}
+
| latest_release_date    = {{Start date and age|2020|12|15|df=yes}}
 
| latest_test_version    =
 
| latest_test_version    =
 
| latest_test_date      =
 
| latest_test_date      =
 
| typing                = [[Static type|Static]], [[Type system#Safely and unsafely typed systems|unsafe]], [[Nominative type system|nominative]]
 
| typing                = [[Static type|Static]], [[Type system#Safely and unsafely typed systems|unsafe]], [[Nominative type system|nominative]]
 
| implementations        = {{nowraplinks}}[[C++ Builder]], [[clang]], [[Comeau C/C++]], [[GNU Compiler Collection|GCC]], [[Intel C++ Compiler]], [[Microsoft Visual C++]], [[Sun Studio (software)|Sun Studio]]{{nowraplinks end}}
 
| implementations        = {{nowraplinks}}[[C++ Builder]], [[clang]], [[Comeau C/C++]], [[GNU Compiler Collection|GCC]], [[Intel C++ Compiler]], [[Microsoft Visual C++]], [[Sun Studio (software)|Sun Studio]]{{nowraplinks end}}
| dialects              = {{nowraplinks}}[[ISO/IEC 14882|ISO/IEC C++]] 1998, [[ISO/IEC 14882|ISO/IEC C++]] 2003, [[ISO/IEC 14882|ISO/IEC C++]] 2011, [[ISO/IEC 14882|ISO/IEC C++]] 2014, [[ISO/IEC 14882|ISO/IEC C++]] 2017,{{nowraplinks end}}
+
| dialects              = {{nowraplinks}}[[ISO/IEC 14882|ISO/IEC C++]] 1998, [[ISO/IEC 14882|ISO/IEC C++]] 2003, [[ISO/IEC 14882|ISO/IEC C++]] 2011, [[ISO/IEC 14882|ISO/IEC C++]] 2014, [[ISO/IEC 14882|ISO/IEC C++]] 2017, [[ISO/IEC 14882|ISO/IEC C++]] 2020{{nowraplinks end}}
| influenced_by          = [[C (programming language)|C]], [[Simula]], [[Ada (programming language)|Ada 83]], [[ALGOL 68]], [[CLU (programming language)|CLU]], [[ML (programming language)|ML]]<ref name="stroustruptcpppl">{{Cite book | last=Stroustrup | first=Bjarne | title=The C++ Programming Language | year=1997 | edition=Third | chapter=1 | isbn=0201889544 | oclc=59193992 }}</ref>
+
| influenced_by          = [[C (programming language)|C]], [[Simula]], [[Ada (programming language)|Ada 83]], [[ALGOL 68]], [[CLU (programming language)|CLU]], [[ML (programming language)|ML]]<ref name="stroustruptcpppl">{{Cite book | last=Stroustrup | first=Bjarne | title=The C++ Programming Language | year=1997 | edition=Third | <!-- chapter=1 | --> isbn=0201889544 | oclc=59193992 }}</ref>
 
| influenced            = [[Perl]]<!--1987-->, [[LPC (programming language)|LPC]]<!--1989-->, [[Lua]]<!--1993-->, [[Pike (programming language)|Pike]]<!-- 1994 -->, [[Ada (programming language)|Ada 95]]<!--1995-->, [[Java (programming language)|Java]]<!--1995-->, [[PHP]]<!--1995-->, [[D (programming language)|D]]<!--1999-->, [[C99]]<!--1999-->, [[C Sharp (programming language)|C#]]<!--2001-->, [[Falcon (programming language)|Falcon]]<!--2003-->
 
| influenced            = [[Perl]]<!--1987-->, [[LPC (programming language)|LPC]]<!--1989-->, [[Lua]]<!--1993-->, [[Pike (programming language)|Pike]]<!-- 1994 -->, [[Ada (programming language)|Ada 95]]<!--1995-->, [[Java (programming language)|Java]]<!--1995-->, [[PHP]]<!--1995-->, [[D (programming language)|D]]<!--1999-->, [[C99]]<!--1999-->, [[C Sharp (programming language)|C#]]<!--2001-->, [[Falcon (programming language)|Falcon]]<!--2003-->
 
| operating_system      = [[Cross-platform|Cross-platform (multi-platform)]]
 
| operating_system      = [[Cross-platform|Cross-platform (multi-platform)]]
Line 22: Line 22:  
|logo caption=C++ logo used by ISO.}}
 
|logo caption=C++ logo used by ISO.}}
 
[[File:BjarneStroustrup.jpg|right|thumb|Bjarne Stroustrup, the creator of C++]]
 
[[File:BjarneStroustrup.jpg|right|thumb|Bjarne Stroustrup, the creator of C++]]
'''C++''' (pronounced "see plus plus") is a [[computer]] [[programming language]] based on [[C programming language|C]]. It was created for writing programs for many different purposes. In the 1990s, C++ became one of the most used programming languages in the world.
+
'''C++''' (pronounced "see plus plus") is a [[computer]] [[programming language]] based on [[C programming language|C]]. It was created for writing programs for many different purposes. In the 1990s, C++ became one of the most used programming languages in the world. Like C, C++ uses manual memory management (unlike most mainstream languages, where memory management is automatic), while the syntax usually used for it is different.
   −
The C++ programming language was developed by [[Bjarne Stroustrup]] at [[Bell Labs]] in the 1980s, and was originally named "C with classes". The language was planned as an improvement on the [[C programming language]], adding features based on [[object-oriented programming]]. Step by step, a lot of advanced features were added to the language, like [[operator overloading]], [[exception handling]] and [[templates (programming)|templates]].
+
The C++ programming language was developed by [[Bjarne Stroustrup]] at [[Bell Labs]] in the 1980s, and was originally named "C with classes". The language was planned as an improvement on the [[C (programming language)|C]] programming language, adding features based on [[object-oriented programming]]. Step by step, a lot of advanced features were added to the language, like [[exception handling]], [[templates (programming)|templates]], "move semantics" and [[namespace]]s (not full module support, while that was added later) and new [[operator overloading]] capabilities were added in versions C++11 and C++20.
   −
'''[http://www.programstudio.online/2020/05/introduction-to-c.html C++] {{Webarchive|url=https://web.archive.org/web/20200713161758/https://www.programstudio.online/2020/05/introduction-to-c.html |date=2020-07-13 }}''' runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX. '''C++''' is simple and practical approach to describe the concepts of [http://www.programstudio.online/2020/05/introduction-to-c.html '''C++''' for beginners] {{Webarchive|url=https://web.archive.org/web/20200713161758/https://www.programstudio.online/2020/05/introduction-to-c.html |date=2020-07-13 }} to advanced software engineers.
+
C++ runs on a most platforms (all mainstream ones), such as [[Windows]], [[macOS]], and the various versions of UNIX, for example [[Linux]]. [https://web.archive.org/web/20200713161758/https://www.programstudio.online/2020/05/introduction-to-c.html Introduction to C++ language] is a practical approach to describe the concepts of C++ for beginners to advanced software engineers.
    
C++ is a general-purpose programing language which means that it can be used to create different variety of applications. [https://codinggrammar.com/what-is-cpp-used-for/ C++ is used for] variety of application domains.
 
C++ is a general-purpose programing language which means that it can be used to create different variety of applications. [https://codinggrammar.com/what-is-cpp-used-for/ C++ is used for] variety of application domains.
 +
 +
C++20 is the latest version of the standard, which finally added for example module support in December 2020 (while many languages supported modules a decade, if not two or more, earlier). The major compilers have almost complete support for C++20, while almost all default to the older C++17 standard, so a compiler switch is needed to enable the C++20 support the compilers have.
 +
 +
New C++ standards are on a three-year schedule, so the next one, C++23, is expected in 2023, and some compilers already have some (partial) support for that experimental standard. The many earlier C++ standards have each added stuff to the language, almost never taken stuff out, so mostly keeping compatibility with older standards.
    
== Example ==
 
== Example ==
 
The following text is C++ source code and it will write the words "[[Hello world program|Hello World!]]" on the screen when it has been [[compiled language|compiled]] and is executed. This program is typically the first program a programmer would write while learning about programming languages.
 
The following text is C++ source code and it will write the words "[[Hello world program|Hello World!]]" on the screen when it has been [[compiled language|compiled]] and is executed. This program is typically the first program a programmer would write while learning about programming languages.
 +
 
<syntaxhighlight lang="cpp">
 
<syntaxhighlight lang="cpp">
 
// This is a comment. It's for *people* to read, not computers. It's usually used to describe the program.
 
// This is a comment. It's for *people* to read, not computers. It's usually used to describe the program.
Line 46: Line 51:  
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 
This program is similar to the last, except it will add 3 + 2 and print the answer instead of "Hello World!".
 
This program is similar to the last, except it will add 3 + 2 and print the answer instead of "Hello World!".
   Line 55: Line 61:  
     // Print a simple calculation.
 
     // Print a simple calculation.
 
     std::cout << 3 + 2;
 
     std::cout << 3 + 2;
 +
    return 0;
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
    
This program subtracts, multiplies, divides and then prints the answer on the screen.
 
This program subtracts, multiplies, divides and then prints the answer on the screen.
 +
 
<syntaxhighlight lang="cpp">
 
<syntaxhighlight lang="cpp">
 
#include <iostream>
 
#include <iostream>
Line 64: Line 72:  
int main()
 
int main()
 
{
 
{
     // Create and initialize 3 variables, a, b, and c, to 5, 10, and 20.
+
     // Create and initialize three variables, a, b, and c, to 5, 10, and 20.
 
     int a = 5;
 
     int a = 5;
 
     int b = 10;
 
     int b = 10;
Line 73: Line 81:  
     std::cout << a*b*c;
 
     std::cout << a*b*c;
 
     std::cout << a/b/c;
 
     std::cout << a/b/c;
 +
    return 0;
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
== Manual memory management ==
 +
C++ introduced two keywords <code>new</code> and <code>delete</code> for manual memory management (while also keeping compatibility with the old way C uses), and the constructor and destructor concepts. In modern C++ code, using <code>new</code> and <code>delete</code> (and destructors) is no longer preferred in high-level code, rather containers such as <code>std:vector</code> (which at a low level are implemented with <code>new</code> and <code>delete</code>).
    
== References ==
 
== References ==
 
{{reflist}}
 
{{reflist}}
      
{{Tech-stub}}
 
{{Tech-stub}}