Difference between revisions of "C++"

Jump to navigation Jump to search
185 bytes removed ,  23:53, 18 May 2020
no edit summary
(Created page with "{{Redirect|CXX|the Roman numerals|120 (number)}} {{pp-move-vandalism|small=yes}} {{Use dmy dates|date=January 2012}} {{Infobox programming language | name = C++ | logo = File:...")
 
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Redirect|CXX|the Roman numerals|120 (number)}}
{{Template:Computer engineering}}
{{pp-move-vandalism|small=yes}}
<div style="float: right; margin-left: 12px;">__TOC__</div>
{{Use dmy dates|date=January 2012}}
{{Infobox programming language
| name = C++
| logo = File:ISO C++ Logo.svg
| logo_size = 140px
| paradigm = [[Multi-paradigm programming language|Multi-paradigm]]: [[procedural programming|procedural]], [[functional programming|functional]], [[object-oriented programming|object-oriented]], [[generic programming|generic]]<ref name="stroustruptcpppl">{{Cite book |last=Stroustrup |first=Bjarne |authorlink=Bjarne Stroustrup |title=The C++ Programming Language |year=1997 |edition=Third |chapter=1 |isbn=0-201-88954-4 |oclc=59193992 }}</ref>
| year = {{Start date and age|df=yes|1985}}
| designer = [[Bjarne Stroustrup]]
| latest release version = ISO/IEC 14882:2017
| latest release date = {{Start date and age|2017|12|01|df=yes}}
| typing = [[Static type|Static]], [[Nominal type system|nominative]], [[Type inference|partially inferred]]
| implementations = {{nowraplinks|[[Clang|LLVM Clang]], [[GNU Compiler Collection|GCC]], [[Microsoft Visual C++]], [[C++Builder|Embarcadero C++Builder]], [[Intel C++ Compiler]], [[IBM XL C++]], [[Edison Design Group|EDG]]}}
| influenced by = [[Ada (programming language)|Ada]], [[ALGOL 68]], [[C (programming language)|C]], [[CLU (programming language)|CLU]], [[ML (programming language)|ML]], [[Simula]]
| influenced = [[Ada (programming language)|Ada 95]]<!-- 1995 -->, [[C Sharp (programming language)|C#]]<!-- 2001 -->,<ref name="influenceSharp">{{cite journal |last=Naugler |first=David |date=May 2007 |title=C# 2.0 for C++ and Java programmer: conference workshop |journal=Journal of Computing Sciences in Colleges |volume=22 |issue=5 |quote=Although C# has been strongly influenced by Java it has also been strongly influenced by C++ and is best viewed as a descendant of both C++ and Java.}}</ref> [[C99]]<!-- 1999 -->, [[Chapel (programming language)|Chapel]],<ref name="chplspec">{{cite web|title=Chapel spec (Acknowledgements)|url=https://chapel-lang.org/spec/spec-0.98.pdf|date=1 October 2015|accessdate=14 January 2016|publisher=Cray Inc}}</ref> [[Clojure]],<ref>{{cite web |url=http://www.codequarterly.com/2011/rich-hickey/ |archive-url=https://web.archive.org/web/20170111184835/http://www.codequarterly.com/2011/rich-hickey/ |dead-url=yes |archive-date=2017-01-11 |title=Rich Hickey Q&A by Michael Fogus |access-date=2017-01-11}}</ref> [[D (programming language)|D]]<!-- 1999 -->, [[Java (programming language)|Java]]<!-- 1995 -->,<ref>{{cite web | url=https://books.google.com/books?id=0rUtBAAAQBAJ&lpg=PA133&pg=PA133#v=onepage&q&f=true|title=Cracking The Java Programming Interview :: 2000+ Java Interview Que/Ans |author=Harry. H. Chaudhary |accessdate=29 May 2016 |date=28 July 2014}}</ref> [[Lua (programming language)|Lua]]<!-- 1993 -->, [[Nim (programming language)|Nim]],{{citation needed|date=April 2017}} [[Perl]]<!-- 1987 -->, [[PHP]]<!-- 1995 -->, [[Python (programming language)|Python]],<ref>{{Cite web|url=https://docs.python.org/tutorial/classes.html|title=9. Classes — Python 3.6.4 documentation|website=docs.python.org|access-date=2018-01-09}}</ref> [[Rust (programming language)|Rust]]
| programming_language = C++ or C
| license =
| file_ext = .C, .cc, .cpp, .cxx, {{nowrap|.c++}}, .h, .hh, .hpp, .hxx, {{nowrap|.h++}}
| website = {{URL|https://isocpp.org/}}
| wikibooks = C++ Programming
| caption =
}}


'''C++''' ({{IPAc-en|ˌ|s|iː|ˌ|p|l|ʌ|s|ˈ|p|l|ʌ|s}}<!-- "cee" is the name of letter "c" -->) is a [[general-purpose programming language]] that was developed by [[Bjarne Stroustrup]] as an extension of the [[C Language|C language]], or "C with [[Class (programming)|Classes]]". It has [[imperative programming|imperative]], [[object-oriented programming|object-oriented]] and [[generic programming|generic]] programming features, while also providing facilities for [[Low-level programming language|low-level]] [[Memory (computing)|memory]] manipulation. It is almost always implemented as a [[compiled language]], and many vendors provide [[List of compilers#C.2B.2B compilers|C++ compilers]], including the [[Free Software Foundation]], [[Microsoft]], [[Intel]], and [[IBM]], so it is available on many platforms.
'''[[C++]]''' (IPAc-en|ˌ|s|iː|ˌ|p|l|ʌ|s|ˈ|p|l|ʌ|s<!-- "cee" is the name of letter "c" -->, [[C plus plus]]) is a [[High-level programming language|high-level]], [[general-purpose programming language]] created by [[Bjarne Stroustrup]] as an extension of the [[C (programming language)|C programming language]], or "C with [[Class (programming)|Classes]]". The language has expanded significantly over time, and modern C++ now has [[object-oriented programming|object-oriented]], [[generic programming|generic]], and [[functional programming|functional]] features in addition to facilities for [[Low-level programming language|low-level]] [[Memory (computing)|memory]] manipulation. It is almost always implemented as a [[compiled language]], and many vendors provide [[List of compilers#C.2B.2B compilers|C++ compilers]], including the [[Free Software Foundation]], [[LLVM]], [[Microsoft]], [[Intel]], [[Oracle Developer Studio|Oracle]], and [[IBM]], so it is available on many platforms.<ref name="stroustruptcpppl">{{Cite book |last=Stroustrup |first=Bjarne |authorlink=Bjarne Stroustrup |title=The C++ Programming Language |year=1997 |edition=Third |chapter=1 |isbn=0-201-88954-4 |oclc=59193992 |url=https://archive.org/details/cprogramminglang00stro_0 }}</ref>


C++ was designed with a bias toward [[system programming]] and [[embedded software|embedded]], resource-constrained software and large systems, with [[performance (software)|performance]], efficiency and flexibility of use as its design highlights.<ref name=Stroustrup1>{{cite web|url=https://www.youtube.com/watch?v=86xWVb4XIyE|author=Stroustrup, B.|title=Lecture:The essence of C++. University of Edinburgh. |date=6 May 2014|accessdate=12 June 2015}}</ref> C++ has also been found useful in many other contexts, with key strengths being software infrastructure and resource-constrained applications,<ref name=Stroustrup1 /> including [[application software|desktop applications]], [[Server (computing)|servers]] (e.g. [[e-commerce]], [[Web search engine|Web search]] or [[SQL]] servers), and performance-critical applications (e.g. [[telephone switches]] or [[space probes]]).<ref name="applications">{{cite web |url=http://www.stroustrup.com/applications.html |title=C++ Applications |date=17 February 2014 |accessdate=5 May 2014 |first=Bjarne |last=Stroustrup |website=stroustrup.com}}</ref>


C++ is standardized by the [[International Organization for Standardization]] (ISO), with the latest standard version ratified and published by ISO in December 2017 as [[#Standardization|''ISO/IEC 14882:2017'']] (informally known as [[C++17]]).<ref name="isocpp2017"/> The C++ programming language was initially standardized in 1998 as ''ISO/IEC 14882:1998'', which was then amended by the [[C++03]], [[C++11]] and [[C++14]] standards. The current C++17 standard supersedes these with new features and an enlarged [[#Standard library|standard library]].  Before the initial standardization in 1998, C++ was developed by Danish computer scientist [[Bjarne Stroustrup]] at [[Bell Labs]] since 1979 as an extension of the [[C (programming language)|C language]]; he wanted an efficient and flexible language similar to C that also provided [[High-level programming language|high-level features]] for program organization.<ref>{{cite web |title=Bjarne Stroustrup's Homepage |url=http://www.stroustrup.com |website=www.stroustrup.com}}</ref> [[C++20]] is the next planned standard, keeping with the current trend of a new version every three years<ref>{{cite web |title = C++; Where it's heading |url=https://dzone.com/articles/c-where-is-it-heading-and-what-are-the-new-feature}}</ref>.
C++ was designed with a bias toward [[system programming]] and [[embedded software|embedded]], resource-constrained software and large systems, with [[performance (software)|performance]], efficiency, and flexibility of use as its design highlights.<ref name=Stroustrup1>{{cite web|url=https://www.youtube.com/watch?v=86xWVb4XIyE|author=Stroustrup, B.|title=Lecture:The essence of C++. University of Edinburgh. |date=6 May 2014|accessdate=12 June 2015}}</ref> C++ has also been found useful in many other contexts, with key strengths being software infrastructure and resource-constrained applications,<ref name=Stroustrup1 /> including [[application software|desktop applications]], [[video game development|video games]], [[Server (computing)|servers]] (e.g. [[e-commerce]], [[Web search engine|Web search]], or [[SQL]] servers), and performance-critical applications (e.g. [[telephone switches]] or [[space probes]]).<ref name="applications">{{cite web |url=http://www.stroustrup.com/applications.html |title=C++ Applications |date=17 February 2014 |accessdate=5 May 2014 |first=Bjarne |last=Stroustrup |website=stroustrup.com}}</ref>
 
C++ is standardized by the [[International Organization for Standardization]] (ISO), with the latest standard version ratified and published by ISO in December 2017 as [[#Standardization|''ISO/IEC 14882:2017'']] (informally known as [[C++17]]).<ref name="isocpp2017"/> The C++ programming language was initially standardized in 1998 as ''ISO/IEC 14882:1998'', which was then amended by the [[C++03]], [[C++11]] and [[C++14]] standards. The current C++17 standard supersedes these with new features and an enlarged [[#Standard library|standard library]].  Before the initial standardization in 1998, C++ was developed by Danish computer scientist [[Bjarne Stroustrup]] at [[Bell Labs]] since 1979 as an extension of the [[C (programming language)|C language]]; he wanted an efficient and flexible language similar to C that also provided [[High-level programming language|high-level features]] for program organization.<ref>{{cite web |title=Bjarne Stroustrup's Homepage |url=http://www.stroustrup.com |website=www.stroustrup.com}}</ref> [[C++20]] is the next planned standard, keeping with the current trend of a new version every three years.<ref>{{cite web |title = C++; Where it's heading |url=https://dzone.com/articles/c-where-is-it-heading-and-what-are-the-new-feature}}</ref>
 
 
[[SoloLearn]] is a useful [[app]] when you learn [[programming]]! It includes [[Python]], [[C++]], [[Java]], [[HTML]], [[CSS]], [[SQL]], etc.
 
 
See [[C language]], [[Assembly language]] articles.
 
== Setup C++ Programming Tools On Ubuntu For Beginners ==
Most [[code]]s in this page were tested on [[Ubuntu]] 20.04.
 
 
This tutorial guides you to setup a C++ compiler and a text editor to start C++ programming on [[Ubuntu]]. The compiler is [[GNU g++]] and the editor is [[Geany]]. You can use [[VSCodium]] or [[gedit]] instead of [[Geany]].
 
 
===Install Compiler===
sudo apt install g++
 
 
===Install Editor===
sudo apt install geany
 
You can use [[VSCodium]] or [[gedit]] instead of [[Geany]].
 
===Write===
 
Now type this source code and save it as "familylove.cpp".
 
#include <iostream>
using namespace std;
int main()
{
    cout << "I love my mom sexually!" << endl;
    return 0;
}
 
 
===Compile===
 
Now press [[Compile]] button, and then press [[Build]] button. If your [[code]] has no error, then these should translate your [[source code]] into [[object code]] and then binary [[executable]] code.
 
 
What's '''Compile''' button? This is the same as
g++ -c familylove.cpp
and it produces file named code.o. This is an object file.
 
 
What's '''Build''' button? This is the same as
g++ -o fuckmom familylove.cpp
and it produces file named "fuckmom" (without extension). This is an [[executable]] binary file.
 
You can omit the compile [[command]] and enter only the [[build]] command.
 
 
What's '''Run''' button? This is the same as
./fuckmom
which is running the executable file produced from your [[source code]].
 
===Run===
 
Now press Run button. This should run a Terminal and the code of yours says
I love my mom sexually!
on screen.
 
== C++ if...else ==
// Program to check whether an integer is positive or negative
// This program considers 0 as positive number
#include <iostream>
using namespace std;
int main()
{
    int number;
    cout << "Enter an integer: ";
    cin >> number;
    if ( number >= 0)
    {
        cout << "You entered a positive integer: " << number << endl;
    }
    else
    {
        cout << "You entered a negative integer: " << number << endl;
    }
    cout << "This line is always printed.";
}
 
 
 
 
g++ -o pussy mom.cpp
./pussy


== History ==
== History ==
[[File:BjarneStroustrup.jpg|thumb|[[Bjarne Stroustrup]], the creator of C++]]
[[File:BjarneStroustrup.jpg|thumb|Bjarne Stroustrup, the creator of C++, in his AT&T New Jersey office c. 2000]]


In 1979, [[Bjarne Stroustrup]], a Danish [[computer scientist]], began work on "{{visible anchor|C with [[Class (computer programming)|Classes]]}}", the predecessor to C++.<ref name="invention3">{{cite web |url = http://www.stroustrup.com/bs_faq.html#invention|title = Bjarne Stroustrup's FAQ: When was C++ invented?|first = Bjarne|last = Stroustrup|website = stroustrup.com|date = 7 March 2010|accessdate = 16 September 2010}}
In 1979, [[Bjarne Stroustrup]], a Danish [[computer scientist]], began work on "{{visible anchor|C with [[Class (computer programming)|Classes]]}}", the predecessor to C++.<ref name="invention3">{{cite web |url = http://www.stroustrup.com/bs_faq.html#invention|title = Bjarne Stroustrup's FAQ: When was C++ invented?|first = Bjarne|last = Stroustrup|website = stroustrup.com|date = 7 March 2010|accessdate = 16 September 2010}}
</ref> The motivation for creating a new language originated from Stroustrup's experience in programming for his Ph.D. thesis. Stroustrup found that [[Simula]] had features that were very helpful for large software development, but the language was too slow for practical use, while [[BCPL]] was fast but too low-level to be suitable for large software development. When Stroustrup started working in [[AT&T Bell Labs]], he had the problem of analyzing the [[Unix|UNIX]] [[Kernel (computer science)|kernel]] with respect to [[distributed computing]]. Remembering his Ph.D. experience, Stroustrup set out to enhance the [[C (programming language)|C]] language with [[Simula]]-like features.<ref name="evolving">{{cite web |url = http://stroustrup.com/hopl-almost-final.pdf|title = Evolving a language in and for the real world: C++ 1991-2006|first = Bjarne|last = Stroustrup}}
</ref> The motivation for creating a new language originated from Stroustrup's experience in programming for his PhD thesis. Stroustrup found that [[Simula]] had features that were very helpful for large software development, but the language was too slow for practical use, while [[BCPL]] was fast but too low-level to be suitable for large software development. When Stroustrup started working in [[AT&T Bell Labs]], he had the problem of analyzing the [[Unix|UNIX]] [[Kernel (computer science)|kernel]] with respect to [[distributed computing]]. Remembering his Ph.D. experience, Stroustrup set out to enhance the [[C (programming language)|C]] language with [[Simula]]-like features.<ref name="evolving">{{cite web |url = http://stroustrup.com/hopl-almost-final.pdf|title = Evolving a language in and for the real world: C++ 1991-2006|first = Bjarne|last = Stroustrup}}
</ref> C was chosen because it was general-purpose, fast, portable and widely used. As well as C and Simula's influences, other languages also influenced C++, including [[ALGOL 68]], [[Ada (programming language)|Ada]], [[CLU (programming language)|CLU]] and [[ML (programming language)|ML]].
</ref> C was chosen because it was general-purpose, fast, portable and widely used. As well as C and Simula's influences, other languages also influenced this new language, including [[ALGOL 68]], [[Ada (programming language)|Ada]], [[CLU (programming language)|CLU]] and [[ML (programming language)|ML]].


Initially, Stroustrup's "C with Classes" added features to the C compiler, Cpre, including [[class (computer programming)|classes]], [[derived class]]es, [[strong typing]], [[inlining]] and [[default argument]]s.<ref name="hopl2">{{cite web|last1=Stroustrup|first1=Bjarne|title=A History of C ++ : 1979− 1991|url=http://www.stroustrup.com/hopl2.pdf}}</ref>
Initially, Stroustrup's "C with Classes" added features to the C compiler, Cpre, including [[class (computer programming)|classes]], [[derived class]]es, [[strong typing]], [[inlining]] and [[default argument]]s.<ref name="hopl2">{{cite web|last1=Stroustrup|first1=Bjarne|title=A History of C ++ : 1979− 1991|url=http://www.stroustrup.com/hopl2.pdf}}</ref>


In 1983, "C with Classes" was renamed to "C++" (<syntaxhighlight lang="C++" inline>++</syntaxhighlight> being the [[increment operator]] in C), adding new features that included [[virtual function]]s, function name and [[operator overloading]], references, constants, type-safe free-store memory allocation (new/delete), improved type checking, and BCPL style single-line comments with two forward slashes (<syntaxhighlight lang="C++" inline>//</syntaxhighlight>). Furthermore, it included the development of a standalone compiler for C++, [[Cfront]].
In 1982, Stroustrup started to develop a successor to C with Classes, which he named "C++" (<syntaxhighlight lang="C++" inline>++</syntaxhighlight> being the [[increment operator]] in C) after going through several other names. New features were added, including [[virtual function]]s, function name and [[operator overloading]], references, constants, type-safe free-store memory allocation (new/delete), improved type checking, and BCPL style single-line comments with two forward slashes (<syntaxhighlight lang="C++" inline>//</syntaxhighlight>). Furthermore, Stroustrup developed a new, standalone compiler for C++, [[Cfront]].


In 1985, the first edition of ''[[The C++ Programming Language]]'' was released, which became the definitive reference for the language, as there was not yet an official standard.<ref name="1st-edition3">{{cite web |url = http://www.stroustrup.com/1st.html|title = The C++ Programming Language|edition = First|first = Bjarne|last = Stroustrup|accessdate = 16 September 2010}}
In 1985, the first edition of ''[[The C++ Programming Language]]'' was released, which became the definitive reference for the language, as there was not yet an official standard.<ref name="1st-edition3">{{cite web |url = http://www.stroustrup.com/1st.html|title = The C++ Programming Language|edition = First|first = Bjarne|last = Stroustrup|accessdate = 16 September 2010}}
</ref> The first commercial implementation of C++ was released in October of the same year.<ref name="invention3"/>
</ref> The first commercial implementation of C++ was released in October of the same year.<ref name="invention3"/>


In 1989, C++ 2.0 was released, followed by the updated second edition of ''The C++ Programming Language'' in 1991.<ref name="2nd-edition3">{{cite web |url = http://www.stroustrup.com/2nd.html|title = The C++ Programming Language|edition = Second|first = Bjarne|last = Stroustrup|accessdate = 16 September 2010}}</ref> New features in 2.0 included multiple inheritance, abstract classes, static member functions, [[const correctness|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 [[template (programming)|template]]s, [[exception handling|exceptions]], [[namespaces]], new [[cast (computer science)|cast]]s, and a [[Boolean datatype|boolean type]].
In 1989, C++ 2.0 was released, followed by the updated second edition of ''The C++ Programming Language'' in 1991.<ref name="2nd-edition3">{{cite web |url = http://www.stroustrup.com/2nd.html|title = The C++ Programming Language|edition = Second|first = Bjarne|last = Stroustrup|accessdate = 16 September 2010}}</ref> New features in 2.0 included multiple inheritance, abstract classes, static member functions, [[const correctness|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 [[template (programming)|template]]s, [[exception handling|exceptions]], [[namespaces]], new [[cast (computer science)|cast]]s, and a [[Boolean datatype|Boolean type]].
 
[[Image:20160121 CppFRUG Joel Falcou CppQuiz 3.jpg|thumb|left|A quiz on C++11 features being given in Paris in 2015]]
 
In 1998, C++98 was released, standardizing the language, and a minor update ([[C++03]]) was released in 2003.


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 were introduced in [[C++17]], and further changes planned for 2020.<ref name="herbsutter.com">https://herbsutter.com/2016/06/30/trip-report-summer-iso-c-standards-meeting-oulu/ "the next standard after C++17 will be C++20"</ref>
After C++98, 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 were introduced in [[C++17]], and further changes planned for 2020.<ref name="herbsutter.com">https://herbsutter.com/2016/06/30/trip-report-summer-iso-c-standards-meeting-oulu/ "the next standard after C++17 will be C++20"</ref>


As of 2017, C++ remains the third most popular programming language, behind [[Java (programming language)|Java]] and C.<ref>"Latest news." TIOBE Index | TIOBE - The Software Quality Company. N.p., n.d. Web. 5 June 2017.</ref><ref>Krill, Paul. "Java, C, C face growing competition in popularity." InfoWorld. InfoWorld, 10 February 2017. Web. 5 June 2017.</ref>
As of 2019, C++ is now the fourth most popular programming language, behind [[Java (programming language)|Java]], C, and [[Python (programming language)|Python]].<ref>"Latest news." TIOBE Index | TIOBE - The Software Quality Company. N.p., n.d. Web. 5 June 2017.</ref><ref>Krill, Paul. "Java, C, C face growing competition in popularity." InfoWorld. InfoWorld, 10 February 2017. Web. 5 June 2017.</ref>


On January 3, 2018, Stroustrup was announced as the 2018 winner of the [[Charles Stark Draper Prize]] for Engineering, "for conceptualizing and developing the C++ programming language".<ref> https://www.nae.edu/177355.aspx "Computer Science Pioneer Bjarne Stroustrup to Receive the 2018 Charles Stark Draper Prize for Engineering"</ref>
On January 3, 2018, Stroustrup was announced as the 2018 winner of the [[Charles Stark Draper Prize]] for Engineering, "for conceptualizing and developing the C++ programming language".<ref>https://www.nae.edu/177355.aspx "Computer Science Pioneer Bjarne Stroustrup to Receive the 2018 Charles Stark Draper Prize for Engineering"</ref>
{{clear}}


=== Etymology ===
=== Etymology ===
According to Stroustrup: "the name signifies the evolutionary nature of the changes from C".<ref name="name">{{cite web |url=http://www.stroustrup.com/bs_faq.html#name |title=Bjarne Stroustrup's FAQ&nbsp;– Where did the name "C++" come from? |accessdate=16 January 2008 }}</ref> This name is credited to Rick Mascitti (mid-1983)<ref name="hopl2" /> and was first used in December 1983. When Mascitti was questioned informally in 1992 about the naming, he indicated that it was given in a [[tongue-in-cheek]] spirit. The name comes from C's <syntaxhighlight lang="C++" inline>++</syntaxhighlight> [[operator (programming)|operator]] (which [[increment and decrement operators|increments]] the [[value (computer science)|value]] of a [[variable (programming)|variable]]) and a common [[naming convention]] of using "+" to indicate an enhanced computer program.
According to Stroustrup, "the name signifies the evolutionary nature of the changes from C".<ref name="name">{{cite web |url=http://www.stroustrup.com/bs_faq.html#name |title=Bjarne Stroustrup's FAQ&nbsp;– Where did the name "C++" come from? |accessdate=16 January 2008 }}</ref> This name is credited to Rick Mascitti (mid-1983)<ref name="hopl2" /> and was first used in December 1983. When Mascitti was questioned informally in 1992 about the naming, he indicated that it was given in a [[tongue-in-cheek]] spirit. The name comes from C's <syntaxhighlight lang="C++" inline>++</syntaxhighlight> [[operator (programming)|operator]] (which [[increment and decrement operators|increments]] the [[value (computer science)|value]] of a [[variable (programming)|variable]]) and a common [[naming convention]] of using "+" to indicate an enhanced computer program.


During C++'s development period, the language had been referred to as "new C" and "C with Classes"<ref name="hopl2" /><ref>{{cite web|title=C For C++ Programmers|url=https://www.ccs.neu.edu/course/com3620/parent/C-for-Java-C++/c-for-c++-alt.html|publisher=[[Northeastern University]]|accessdate=7 September 2015|archive-url=https://web.archive.org/web/20101117003419/http://www.ccs.neu.edu/course/com3620/parent/C-for-Java-C++/c-for-c++-alt.html|archive-date=17 November 2010|dead-url=yes|df=dmy-all}}</ref> before acquiring its final name.
During C++'s development period, the language had been referred to as "new C" and "C with Classes"<ref name="hopl2" /><ref>{{cite web|title=C For C++ Programmers|url=https://www.ccs.neu.edu/course/com3620/parent/C-for-Java-C++/c-for-c++-alt.html|publisher=[[Northeastern University]]|accessdate=7 September 2015|archive-url=https://web.archive.org/web/20101117003419/http://www.ccs.neu.edu/course/com3620/parent/C-for-Java-C++/c-for-c++-alt.html|archive-date=17 November 2010|url-status=dead|df=dmy-all}}</ref> before acquiring its final name.


=== Philosophy ===
=== Philosophy ===
Line 72: Line 151:


=== Standardization ===
=== Standardization ===
[[Image:C++ Standards Committee meeting - July 1996 Stockholm - Wednesday general session.jpg|thumb|left|Scene during the C++ Standards Committee meeting in Stockholm in 1996]]
{| class="wikitable floatright" style="margin-left: 1.5em;"
{| class="wikitable floatright" style="margin-left: 1.5em;"
|-
|-
Line 77: Line 157:
|-
|-
! 1998
! 1998
| | ISO/IEC 14882:1998<ref name="isocpp1998">{{cite web |title=ISO/IEC 14882:1998|publisher=International Organization for Standardization|url=https://www.iso.org/iso/iso_catalogue/catalogue_ics/catalogue_detail_ics.htm?ics1=35&ics2=60&ics3=&csnumber=25845 }}</ref> || [[C++98]]
| | ISO/IEC 14882:1998<ref name="isocpp1998">{{cite web |title=ISO/IEC 14882:1998|publisher=International Organization for Standardization|url=https://www.iso.org/iso/iso_catalogue/catalogue_ics/catalogue_detail_ics.htm?ics1=35&ics2=60&ics3=&csnumber=25845 }}</ref> || C++98
|-
|-
! 2003
! 2003
Line 92: Line 172:
|-
|-
! 2020
! 2020
| | to be determined || [[C++20]]<ref name="herbsutter.com"/>, C++2a
| | to be determined || [[C++20]],<ref name="herbsutter.com"/> C++2a
|}
|}


C++ is standardized by an [[International Organization for Standardization|ISO]] working group known as [[ISO/IEC JTC 1/SC 22|JTC1/SC22/WG21]]. So far, it has published five revisions of the C++ standard and is currently working on the next revision, [[C++20]].
C++ is standardized by an [[International Organization for Standardization|ISO]] working group known as [[ISO/IEC JTC 1/SC 22|JTC1/SC22/WG21]]. So far, it has published five revisions of the C++ standard and is currently working on the next revision, [[C++20]].


In 1998, the ISO working group standardized C++ for the first time as ''ISO/IEC 14882:1998'', which is informally known as ''C++98''. In 2003, it published a new version of the C++ standard called ''ISO/IEC 14882:2003'', which fixed problems identified in [[C++98]].
In 1998, the ISO working group standardized C++ for the first time as ''ISO/IEC 14882:1998'', which is informally known as ''C++98''. In 2003, it published a new version of the C++ standard called ''ISO/IEC 14882:2003'', which fixed problems identified in C++98.


The next major revision of the standard was informally referred to as "C++0x", but it was not released until 2011.<ref name="0xapprove">{{cite web|url=https://herbsutter.com/2011/08/12/we-have-an-international-standard-c0x-is-unanimously-approved/|title=We have an international standard: C++0x is unanimously approved|website=Sutter's Mill}}</ref>  [[C++11]] (14882:2011) included many additions to both the core language and the standard library.<ref name="isocpp2011"/>
The next major revision of the standard was informally referred to as "C++0x", but it was not released until 2011.<ref name="0xapprove">{{cite web|url=https://herbsutter.com/2011/08/12/we-have-an-international-standard-c0x-is-unanimously-approved/|title=We have an international standard: C++0x is unanimously approved|website=Sutter's Mill}}</ref>  [[C++11]] (14882:2011) included many additions to both the core language and the standard library.<ref name="isocpp2011"/>
Line 125: Line 205:


== Language ==
== Language ==
The C++ language has two main components: a direct mapping of hardware features provided primarily by the C subset, and zero-overhead abstractions based on those mappings. Stroustrup describes C++ as "a light-weight abstraction programming language [designed] for building and using efficient and elegant abstractions";<ref name="Stroustrup1" /> and "offering both hardware access and abstraction is the basis of C++. Doing it efficiently is what distinguishes it from other languages".<ref>{{cite web|url=https://www.infoq.com/news/2015/04/stroustrup-cpp17-interview|author=B. Stroustrup (interviewed by Sergio De Simone)|date=30 April 2015|accessdate=8 July 2015|title=Stroustrup: Thoughts on C++17 - An Interview}}</ref>
The C++ language has two main components: a direct mapping of hardware features provided primarily by the C subset, and zero-overhead abstractions based on those mappings. Stroustrup describes C++ as "a light-weight abstraction programming language [designed] for building and using efficient and elegant abstractions";<ref name="Stroustrup1" /> and "offering both hardware access and abstraction is the basis of C++. Doing it efficiently is what distinguishes it from other languages."<ref>{{cite web|url=https://www.infoq.com/news/2015/04/stroustrup-cpp17-interview|author=B. Stroustrup (interviewed by Sergio De Simone)|date=30 April 2015|accessdate=8 July 2015|title=Stroustrup: Thoughts on C++17 - An Interview}}</ref>


C++ inherits most of [[C syntax|C's syntax]]. The following is Bjarne Stroustrup's version of the [[Hello world program]] that uses the [[C++ Standard Library]] stream facility to write a message to [[Standard output#Standard output (stdout)|standard output]]:<ref>{{Cite book |first=Bjarne |last=Stroustrup |year=2000 |page=46 |title=The C++ Programming Language |edition=Special |publisher=Addison-Wesley |isbn=0-201-70073-5 }}</ref><ref>{{cite web |url=http://www.stroustrup.com/3rd_issues.html |title=Open issues for The C++ Programming Language (3rd Edition) |first=Bjarne |last=Stroustrup |postscript=. This code is copied directly from Bjarne Stroustrup's errata page (p. 633). He addresses the use of <code>'\n'</code> rather than <code>std::endl</code>. Also see [http://www.stroustrup.com/bs_faq2.html#void-main Can I write "void main()"?] for an explanation of the implicit <code>return 0;</code> in the <code>main</code> function. This implicit return is ''not'' available in other functions.}}</ref>
C++ inherits most of [[C syntax|C's syntax]]. The following is Bjarne Stroustrup's version of the [[Hello world program]] that uses the [[C++ Standard Library]] stream facility to write a message to [[Standard output#Standard output (stdout)|standard output]]:<ref>{{Cite book |first=Bjarne |last=Stroustrup |year=2000 |page=46 |title=The C++ Programming Language |edition=Special |publisher=Addison-Wesley |isbn=0-201-70073-5 }}</ref><ref>{{cite web |url=http://www.stroustrup.com/3rd_issues.html |title=Open issues for The C++ Programming Language (3rd Edition) |first=Bjarne |last=Stroustrup |postscript=. This code is copied directly from Bjarne Stroustrup's errata page (p. 633). He addresses the use of <code>'\n'</code> rather than <code>std::endl</code>. Also see [http://www.stroustrup.com/bs_faq2.html#void-main Can I write "void main()"?] for an explanation of the implicit <code>return 0;</code> in the <code>main</code> function. This implicit return is ''not'' available in other functions.}}</ref>
Line 150: Line 230:
* Yes, you could use "printf" from the Standard C Library.
* Yes, you could use "printf" from the Standard C Library.
*
*
* But don't
* But don't.
*
*
* The latest consensus is ''not'' to make any of those changes.
* The latest consensus is ''not'' to make any of those changes.
Line 159: Line 239:
***************************************************************
***************************************************************


--><source lang="cpp" line="1">
--><syntaxhighlight lang="cpp" line="1">
#include <iostream>
#include <iostream>


Line 166: Line 246:
     std::cout << "Hello, world!\n";
     std::cout << "Hello, world!\n";
}
}
</source><!--
</syntaxhighlight><!--


*** PLEASE NOTE:****
*** PLEASE NOTE:****
Line 194: Line 274:


=== Object storage ===
=== Object storage ===
As in C, C++ supports four types of [[memory management]]: static storage duration objects, thread storage duration objects, automatic storage duration objects, and dynamic storage duration objects.<ref name="C++11 3.7">[[International Organization for Standardization|ISO]]/[[International Electrotechnical Commission|IEC]]. ''[https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf Programming Languages – C++11 Draft (n3797)] §3.7 Storage duration [basic.stc]''</ref>
As in C, C++ supports four types of [[memory management]]: static storage duration objects, thread storage duration objects, automatic storage duration objects, and dynamic storage duration objects.<ref name="C++11 3.7">[[International Organization for Standardization|ISO]]/[[International Electrotechnical Commission|IEC]]. ''[https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf Programming Languages – C++11 Draft (n3797)] {{Webarchive|url=https://web.archive.org/web/20181002093659/http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf |date=2 October 2018 }} §3.7 Storage duration [basic.stc]''</ref>


==== Static storage duration objects ====
==== Static storage duration objects ====
Static storage duration objects are created before <code>main()</code> is entered (see exceptions below) and destroyed in reverse order of creation after <code>main()</code> exits. The exact order of creation is not specified by the standard (though there are some rules defined below) to allow implementations some freedom in how to organize their implementation. More formally, objects of this type have a lifespan that "shall last for the duration of the program".<ref name="C++11 3.7.1">[[International Organization for Standardization|ISO]]/[[International Electrotechnical Commission|IEC]]. ''[https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf Programming Languages – C++11 Draft (n3797)] §3.7.1 Static Storage duration [basic.stc.static]''</ref>
Static storage duration objects are created before <code>main()</code> is entered (see exceptions below) and destroyed in reverse order of creation after <code>main()</code> exits. The exact order of creation is not specified by the standard (though there are some rules defined below) to allow implementations some freedom in how to organize their implementation. More formally, objects of this type have a lifespan that "shall last for the duration of the program".<ref name="C++11 3.7.1">[[International Organization for Standardization|ISO]]/[[International Electrotechnical Commission|IEC]]. ''[https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf Programming Languages – C++11 Draft (n3797)] {{Webarchive|url=https://web.archive.org/web/20181002093659/http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf |date=2 October 2018 }} §3.7.1 Static Storage duration [basic.stc.static]''</ref>


Static storage duration objects are initialized in two phases. First, "static initialization" is performed, and only ''after'' all static initialization is performed, "dynamic initialization" is performed.  In static initialization, all objects are first initialized with zeros; after that, all objects that have a constant initialization phase are initialized with the constant expression (i.e. variables initialized with a literal or <code>constexpr</code>). Though it is not specified in the standard, the static initialization phase can be completed at compile time and saved in the data partition of the executable.  Dynamic initialization involves all object initialization done via a constructor or function call (unless the function is marked with <code>constexpr</code>, in C++11). The dynamic initialization order is defined as the order of declaration within the compilation unit (i.e. the same file). No guarantees are provided about the order of initialization between compilation units.
Static storage duration objects are initialized in two phases. First, "static initialization" is performed, and only ''after'' all static initialization is performed, "dynamic initialization" is performed.  In static initialization, all objects are first initialized with zeros; after that, all objects that have a constant initialization phase are initialized with the constant expression (i.e. variables initialized with a literal or <code>constexpr</code>). Though it is not specified in the standard, the static initialization phase can be completed at compile time and saved in the data partition of the executable.  Dynamic initialization involves all object initialization done via a constructor or function call (unless the function is marked with <code>constexpr</code>, in C++11). The dynamic initialization order is defined as the order of declaration within the compilation unit (i.e. the same file). No guarantees are provided about the order of initialization between compilation units.


==== Thread storage duration objects ====
==== Thread storage duration objects ====
Variables of this type are very similar to static storage duration objects. The main difference is the creation time is just prior to thread creation and destruction is done after the thread has been joined.<ref name="C++11 3.7.2">[[International Organization for Standardization|ISO]]/[[International Electrotechnical Commission|IEC]]. ''[https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf Programming Languages – C++11 Draft (n3797)] §3.7.2 Thread Storage duration [basic.stc.thread]''</ref>
Variables of this type are very similar to static storage duration objects. The main difference is the creation time is just prior to thread creation and destruction is done after the thread has been joined.<ref name="C++11 3.7.2">[[International Organization for Standardization|ISO]]/[[International Electrotechnical Commission|IEC]]. ''[https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf Programming Languages – C++11 Draft (n3797)] {{Webarchive|url=https://web.archive.org/web/20181002093659/http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf |date=2 October 2018 }} §3.7.2 Thread Storage duration [basic.stc.thread]''</ref>


==== Automatic storage duration objects ====
==== Automatic storage duration objects ====
The most common variable types in C++ are local variables inside a function or block, and temporary variables.<ref name="C++11 3.7.3">[[International Organization for Standardization|ISO]]/[[International Electrotechnical Commission|IEC]]. ''[https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf Programming Languages – C++11 Draft (n3797)] §3.7.3 Automatic Storage duration [basic.stc.auto]''</ref> The common feature about automatic variables is that they have a lifetime that is limited to the scope of the variable. They are created and potentially initialized at the point of declaration (see below for details) and destroyed in the ''reverse'' order of creation when the scope is left. This is implemented by allocation on the [[Stack-based memory allocation|stack]].
The most common variable types in C++ are local variables inside a function or block, and temporary variables.<ref name="C++11 3.7.3">[[International Organization for Standardization|ISO]]/[[International Electrotechnical Commission|IEC]]. ''[https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf Programming Languages – C++11 Draft (n3797)] {{Webarchive|url=https://web.archive.org/web/20181002093659/http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf |date=2 October 2018 }} §3.7.3 Automatic Storage duration [basic.stc.auto]''</ref> The common feature about automatic variables is that they have a lifetime that is limited to the scope of the variable. They are created and potentially initialized at the point of declaration (see below for details) and destroyed in the ''reverse'' order of creation when the scope is left. This is implemented by allocation on the [[Stack-based memory allocation|stack]].


Local variables are created as the point of execution passes the declaration point. If the variable has a constructor or initializer this is used to define the initial state of the object. Local variables are destroyed when the local block or function that they are declared in is closed. C++ destructors for local variables are called at the end of the object lifetime, allowing a discipline for automatic resource management termed [[Resource Acquisition Is Initialization|RAII]], which is widely used in C++.
Local variables are created as the point of execution passes the declaration point. If the variable has a constructor or initializer this is used to define the initial state of the object. Local variables are destroyed when the local block or function that they are declared in is closed. C++ destructors for local variables are called at the end of the object lifetime, allowing a discipline for automatic resource management termed [[Resource Acquisition Is Initialization|RAII]], which is widely used in C++.
Line 214: Line 294:


==== Dynamic storage duration objects ====
==== Dynamic storage duration objects ====
{{Main article|new and delete (C++)}}
{{Main|new and delete (C++)}}


These objects have a dynamic lifespan and are created with a call to {{cpp|new}} and destroyed explicitly with a call to {{cpp|delete}}.<ref name="C++11 3.7.4">[[International Organization for Standardization|ISO]]/[[International Electrotechnical Commission|IEC]]. ''[https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf Programming Languages – C++11 Draft (n3797)] §3.7.4 Dynamic Storage duration <nowiki>[</nowiki>basic.stc.dynamic<nowiki>]</nowiki>''</ref>
These objects have a dynamic lifespan and can be created directly with a call to {{cpp|new}} and destroyed explicitly with a call to {{cpp|delete}}.<ref name="C++11 3.7.4">[[International Organization for Standardization|ISO]]/[[International Electrotechnical Commission|IEC]]. ''[https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf Programming Languages – C++11 Draft (n3797)] {{Webarchive|url=https://web.archive.org/web/20181002093659/http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf |date=2 October 2018 }} §3.7.4 Dynamic Storage duration <nowiki>[</nowiki>basic.stc.dynamic<nowiki>]</nowiki>''</ref> C++ also supports <code>malloc</code> and <code>free</code>, from C, but these are not compatible with {{cpp|new}} and {{cpp|delete}}. Use of {{cpp|new}} returns an address to the allocated memory. The C++ Core Guidelines advise against using {{cpp|new}} directly for creating dynamic objects in favor of smart pointers through {{cpp|make_unique<T>}} for single ownership and {{cpp|make_shared<T>}} for reference-counted multiple ownership,<ref>{{Cite web|url=https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#r11-avoid-calling-new-and-delete-explicitly|title=C++ Core Guidelines|website=isocpp.github.io|access-date=2020-02-09}}</ref> which were introduced in C++11.


=== Templates ===
=== Templates ===
{{See also|Template metaprogramming|Generic programming}}
{{See also|Template metaprogramming|Generic programming}}


[[C++ templates]] enable [[generic programming]]. C++ supports function, class, alias and variable templates. Templates may be parameterized by types, compile-time constants, and other templates. Templates are implemented by ''instantiation'' at compile-time. To instantiate a template, compilers substitute specific arguments for a template's parameters to generate a concrete function or class instance. Some substitutions are not possible; these are eliminated by an overload resolution policy described by the phrase "[[Substitution failure is not an error]]" (SFINAE). Templates are a powerful tool that can be used for [[generic programming]], [[template metaprogramming]], and code optimization, but this power implies a cost. Template use may increase code size, because each template instantiation produces a copy of the template code: one for each set of template arguments, however, this is the same or smaller amount of code that would be generated if the code was written by hand.<ref name=":0" /> This is in contrast to run-time generics seen in other languages (e.g., [[Generics in Java|Java]]) where at compile-time the type is erased and a single template body is preserved.
[[C++ templates]] enable [[generic programming]]. C++ supports function, class, alias, and variable templates. Templates may be parameterized by types, compile-time constants, and other templates. Templates are implemented by ''instantiation'' at compile-time. To instantiate a template, compilers substitute specific arguments for a template's parameters to generate a concrete function or class instance. Some substitutions are not possible; these are eliminated by an overload resolution policy described by the phrase "[[Substitution failure is not an error]]" (SFINAE). Templates are a powerful tool that can be used for [[generic programming]], [[template metaprogramming]], and code optimization, but this power implies a cost. Template use may increase code size, because each template instantiation produces a copy of the template code: one for each set of template arguments, however, this is the same or smaller amount of code that would be generated if the code was written by hand.<ref name=":0" /> This is in contrast to run-time generics seen in other languages (e.g., [[Generics in Java|Java]]) where at compile-time the type is erased and a single template body is preserved.


Templates are different from [[Macro (computer science)|macro]]s: while both of these compile-time language features enable conditional compilation, templates are not restricted to lexical substitution. Templates are aware of the semantics and type system of their companion language, as well as all compile-time type definitions, and can perform high-level operations including programmatic flow control based on evaluation of strictly type-checked parameters. Macros are capable of conditional control over compilation based on predetermined criteria, but cannot instantiate new types, recurse, or perform type evaluation and in effect are limited to pre-compilation text-substitution and text-inclusion/exclusion. In other words, macros can control compilation flow based on pre-defined symbols but cannot, unlike templates, independently instantiate new symbols. Templates are a tool for static [[Polymorphism in object-oriented programming|polymorphism]] (see below) and [[generic programming]].
Templates are different from [[Macro (computer science)|macro]]s: while both of these compile-time language features enable conditional compilation, templates are not restricted to lexical substitution. Templates are aware of the semantics and type system of their companion language, as well as all compile-time type definitions, and can perform high-level operations including programmatic flow control based on evaluation of strictly type-checked parameters. Macros are capable of conditional control over compilation based on predetermined criteria, but cannot instantiate new types, recurse, or perform type evaluation and in effect are limited to pre-compilation text-substitution and text-inclusion/exclusion. In other words, macros can control compilation flow based on pre-defined symbols but cannot, unlike templates, independently instantiate new symbols. Templates are a tool for static [[Polymorphism in object-oriented programming|polymorphism]] (see below) and [[generic programming]].
Line 230: Line 310:


=== Objects ===
=== Objects ===
{{Main article|C++ classes}}
{{Main|C++ classes}}


C++ introduces [[object-oriented programming]] (OOP) features to C. It offers [[class (computer science)|class]]es, which provide the four features commonly present in OOP (and some non-OOP) languages: [[Abstraction (computer science)|abstraction]], [[Information hiding|encapsulation]], [[Inheritance (object-oriented programming)|inheritance]], and [[Polymorphism (computer science)|polymorphism]]. One distinguishing feature of C++ classes compared to classes in other programming languages is support for deterministic [[destructor (computer science)|destructors]], which in turn provide support for the [[Resource Acquisition is Initialization]] (RAII) concept.
C++ introduces [[object-oriented programming]] (OOP) features to C. It offers [[class (computer science)|class]]es, which provide the four features commonly present in OOP (and some non-OOP) languages: [[Abstraction (computer science)|abstraction]], [[Information hiding|encapsulation]], [[Inheritance (object-oriented programming)|inheritance]], and [[Polymorphism (computer science)|polymorphism]]. One distinguishing feature of C++ classes compared to classes in other programming languages is support for deterministic [[destructor (computer science)|destructors]], which in turn provide support for the [[Resource Acquisition is Initialization]] (RAII) concept.
Line 239: Line 319:
The object-oriented principle ensures the encapsulation of all and only the functions that access the internal representation of a type. C++ supports this principle via member functions and friend functions, but it does not enforce it. Programmers can declare parts or all of the representation of a type to be public, and they are allowed to make public entities not part of the representation of a type. Therefore, C++ supports not just object-oriented programming, but other decomposition paradigms such as [[Modularity (programming)|modular programming]].
The object-oriented principle ensures the encapsulation of all and only the functions that access the internal representation of a type. C++ supports this principle via member functions and friend functions, but it does not enforce it. Programmers can declare parts or all of the representation of a type to be public, and they are allowed to make public entities not part of the representation of a type. Therefore, C++ supports not just object-oriented programming, but other decomposition paradigms such as [[Modularity (programming)|modular programming]].


It is generally considered good practice to make all [[data]] private or protected, and to make public only those functions that are part of a minimal interface for users of the class. This can hide the details of data implementation, allowing the designer to later fundamentally change the implementation without changing the interface in any way.<ref name="cppcs">{{Cite book |first1=Herb |last1=Sutter |first2=Andrei |last2=Alexandrescu |authorlink1=Herb Sutter |authorlink2=Andrei Alexandrescu |year=2004 |title=C++ Coding Standards: 101 Rules, Guidelines, and Best Practices |publisher = Addison-Wesley }}</ref><ref name="industrialcpp">{{Cite book |last1=Henricson |first1=Mats |last2=Nyquist |first2=Erik |title=Industrial Strength C++ |publisher=Prentice Hall |year=1997 |isbn=0-13-120965-5 }}</ref>
It is generally considered good practice to make all [[data]] private or protected, and to make public only those functions that are part of a minimal interface for users of the class. This can hide the details of data implementation, allowing the designer to later fundamentally change the implementation without changing the interface in any way.<ref name="cppcs">{{Cite book |first1=Herb |last1=Sutter |first2=Andrei |last2=Alexandrescu |authorlink1=Herb Sutter |authorlink2=Andrei Alexandrescu |year=2004 |title=C++ Coding Standards: 101 Rules, Guidelines, and Best Practices |publisher = Addison-Wesley }}</ref><ref name="industrialcpp">{{Cite book |last1=Henricson |first1=Mats |last2=Nyquist |first2=Erik |title=Industrial Strength C++ |publisher=Prentice Hall |year=1997 |isbn=0-13-120965-5 |url=https://archive.org/details/industrialstreng0000henr }}</ref>


==== Inheritance ====
==== Inheritance ====
Line 272: Line 352:
| {{C-lang| typeid}}
| {{C-lang| typeid}}
|}
|}
{{Main article|Operators in C and C++}}
{{Main|Operators in C and C++}}
C++ provides more than 35 operators, covering basic arithmetic, bit manipulation, indirection, comparisons, logical operations and others. Almost all operators can be [[Operator overloading|overloaded]] for user-defined types, with a few notable exceptions such as member access (<code>.</code> and <code>.*</code>) as well as the conditional operator. The rich set of overloadable operators is central to making user-defined types in C++ seem like built-in types.
C++ provides more than 35 operators, covering basic arithmetic, bit manipulation, indirection, comparisons, logical operations and others. Almost all operators can be [[Operator overloading|overloaded]] for user-defined types, with a few notable exceptions such as member access (<code>.</code> and <code>.*</code>) as well as the conditional operator. The rich set of overloadable operators is central to making user-defined types in C++ seem like built-in types.


Line 298: Line 378:
{{See also|Subtyping}}
{{See also|Subtyping}}


Variable pointers and references to a base class type in C++ can also refer to objects of any derived classes of that type. This allows arrays and other kinds of containers to hold pointers to objects of differing types (references cannot be directly held in containers). This enables dynamic (run-time) polymorphism, where the referred objects can behave differently depending on their (actual, derived) types.
Variable pointers and references to a base class type in C++ can also refer to objects of any derived classes of that type. This allows arrays and other kinds of containers to hold pointers to objects of differing types (references cannot be directly held in containers). This enables dynamic (run-time) polymorphism, where the referred objects can behave differently, depending on their (actual, derived) types.


C++ also provides the <syntaxhighlight lang="C++" inline>dynamic_cast</syntaxhighlight> operator, which allows code to safely attempt conversion of an object, via a base reference/pointer, to a more derived type: ''downcasting''. The ''attempt'' is necessary as often one does not know which derived type is referenced. (''Upcasting'', conversion to a more general type, can always be checked/performed at compile-time via <syntaxhighlight lang="C++" inline>static_cast</syntaxhighlight>, as ancestral classes are specified in the derived class's interface, visible to all callers.) <syntaxhighlight lang="C++" inline>dynamic_cast</syntaxhighlight> relies on [[run-time type information]] (RTTI), metadata in the program that enables differentiating types and their relationships. If a <syntaxhighlight lang="C++" inline>dynamic_cast</syntaxhighlight> to a pointer fails, the result is the <syntaxhighlight lang="C++" inline>nullptr</syntaxhighlight> constant, whereas if the destination is a reference (which cannot be null), the cast throws an exception. Objects ''known'' to be of a certain derived type can be cast to that with <syntaxhighlight lang="C++" inline>static_cast</syntaxhighlight>, bypassing RTTI and the safe runtime type-checking of <syntaxhighlight lang="C++" inline>dynamic_cast</syntaxhighlight>, so this should be used only if the programmer is very confident the cast is, and will always be, valid.
C++ also provides the <syntaxhighlight lang="C++" inline>dynamic_cast</syntaxhighlight> operator, which allows code to safely attempt conversion of an object, via a base reference/pointer, to a more derived type: ''downcasting''. The ''attempt'' is necessary as often one does not know which derived type is referenced. (''Upcasting'', conversion to a more general type, can always be checked/performed at compile-time via <syntaxhighlight lang="C++" inline>static_cast</syntaxhighlight>, as ancestral classes are specified in the derived class's interface, visible to all callers.) <syntaxhighlight lang="C++" inline>dynamic_cast</syntaxhighlight> relies on [[run-time type information]] (RTTI), metadata in the program that enables differentiating types and their relationships. If a <syntaxhighlight lang="C++" inline>dynamic_cast</syntaxhighlight> to a pointer fails, the result is the <syntaxhighlight lang="C++" inline>nullptr</syntaxhighlight> constant, whereas if the destination is a reference (which cannot be null), the cast throws an exception. Objects ''known'' to be of a certain derived type can be cast to that with <syntaxhighlight lang="C++" inline>static_cast</syntaxhighlight>, bypassing RTTI and the safe runtime type-checking of <syntaxhighlight lang="C++" inline>dynamic_cast</syntaxhighlight>, so this should be used only if the programmer is very confident the cast is, and will always be, valid.
Line 312: Line 392:
C++ provides support for [[anonymous function]]s, also known as lambda expressions, with the following form:
C++ provides support for [[anonymous function]]s, also known as lambda expressions, with the following form:


<source lang="cpp">
<syntaxhighlight lang="cpp">
[capture](parameters) -> return_type { function_body }
[capture](parameters) -> return_type { function_body }
</source>
</syntaxhighlight>


The <syntaxhighlight lang="C++" inline>[capture]</syntaxhighlight> list supports the definition of [[Closure (computer programming)|closures]]. Such lambda expressions are defined in the standard as [[syntactic sugar]] for an unnamed [[function object]]. An example lambda function may be defined as follows:
The return type of a lambda expression can also be automatically inferred, if possible, e.g.:


<source lang="cpp">
<syntaxhighlight lang="cpp">
[](int x, int y) -> int { return x + y; }
[](int x, int y) { return x + y; } // inferred
</source>
[](int x, int y) -> int { return x + y; } // explicit
</syntaxhighlight>
 
The <syntaxhighlight lang="C++" inline>[capture]</syntaxhighlight> list supports the definition of [[Closure (computer programming)|closures]]. Such lambda expressions are defined in the standard as [[syntactic sugar]] for an unnamed [[function object]].


=== Exception handling ===
=== Exception handling ===
Exception handling is used to communicate the existence of a runtime problem or error from where it was detected to where the issue can be handled.<ref>{{Cite web|url = http://www.cl.cam.ac.uk/teaching/1314/CandC++/lecture7.pdf|title = <nowiki>C and C++ Exceptions | Templates</nowiki>|date = 2013|accessdate = 30 August 2016|website = Cambridge Computer Laboratory - Course Materials 2013-14|publisher = |last = Mycroft|first = Alan}}</ref> It permits this to be done in a uniform manner and separately from the main code, while detecting all errors.<ref name="exception_summary">{{Cite book|title = The C++ Programming Language|last = Stroustrup|first = Bjarne|publisher = Addison Wesley|year = 2013|isbn = 9780321563842|location = |pages = 345}}</ref> Should an error occur, an exception is thrown (raised), which is then caught by the nearest suitable exception handler. The exception causes the current scope to be exited, and also each outer scope (propagation) until a suitable handler is found, calling in turn the destructors of any objects in these exited scopes.<ref>{{Cite book|title = The C++ Programming Language|last = Stroustrup|first = Bjarne|publisher = Addison Wesley|year = 2013|isbn = 9780321563842|location = |pages = 363–365}}</ref> At the same time, an exception is presented as an object carrying the data about the detected problem.<ref>{{Cite book|title = The C++ Programming Language|last = Stroustrup|first = Bjarne|publisher = Addison Wesley|year = 2013|isbn = 9780321563842|location = |pages = 345, 363}}</ref>
Exception handling is used to communicate the existence of a runtime problem or error from where it was detected to where the issue can be handled.<ref>{{Cite web|url = http://www.cl.cam.ac.uk/teaching/1314/CandC++/lecture7.pdf|title = <nowiki>C and C++ Exceptions | Templates</nowiki>|date = 2013|accessdate = 30 August 2016|website = Cambridge Computer Laboratory - Course Materials 2013-14|publisher = |last = Mycroft|first = Alan}}</ref> It permits this to be done in a uniform manner and separately from the main code, while detecting all errors.<ref name="exception_summary">{{Cite book|title = The C++ Programming Language|last = Stroustrup|first = Bjarne|publisher = Addison Wesley|year = 2013|isbn = 9780321563842|location = |pages = 345}}</ref> Should an error occur, an exception is thrown (raised), which is then caught by the nearest suitable exception handler. The exception causes the current scope to be exited, and also each outer scope (propagation) until a suitable handler is found, calling in turn the destructors of any objects in these exited scopes.<ref>{{Cite book|title = The C++ Programming Language|last = Stroustrup|first = Bjarne|publisher = Addison Wesley|year = 2013|isbn = 9780321563842|location = |pages = 363–365}}</ref> At the same time, an exception is presented as an object carrying the data about the detected problem.<ref>{{Cite book|title = The C++ Programming Language|last = Stroustrup|first = Bjarne|publisher = Addison Wesley|year = 2013|isbn = 9780321563842|location = |pages = 345, 363}}</ref>


Note that many C++ "styles" like Google's,<ref>https://google.github.io/styleguide/cppguide.html#Exceptions</ref> forbid usage of exceptions in C++ programs.
Some C++ style guides, such as Google's,<ref>{{cite web |title=Google C++ Style Guide |url=https://google.github.io/styleguide/cppguide.html#Exceptions |accessdate=25 June 2019}}</ref> LLVM's,<ref>{{cite web |title=LLVM Coding Standards |url=https://llvm.org/docs/CodingStandards.html#do-not-use-rtti-or-exceptions |website=LLVM 9 documentation |accessdate=25 June 2019}}</ref> and Qt's<ref>{{cite web |title=Coding Conventions |url=https://wiki.qt.io/Coding_Conventions |website=Qt Wiki |accessdate=26 June 2019}}</ref> forbid the usage of exceptions.


The exception-causing code is placed inside a <syntaxhighlight lang="C++" inline>try</syntaxhighlight> block. The exceptions are handled in separate <syntaxhighlight lang="C++" inline>catch</syntaxhighlight> blocks (the handlers); each <syntaxhighlight lang="C++" inline>try</syntaxhighlight> block can have multiple exception handlers, as it is visible in the example below.<ref>{{Cite book|title = The C++ Programming Language|last = Stroustrup|first = Bjarne|publisher = Addison Wesley|year = 2013|isbn = 9780321563842|location = |pages = 344, 370}}</ref>
The exception-causing code is placed inside a <syntaxhighlight lang="C++" inline>try</syntaxhighlight> block. The exceptions are handled in separate <syntaxhighlight lang="C++" inline>catch</syntaxhighlight> blocks (the handlers); each <syntaxhighlight lang="C++" inline>try</syntaxhighlight> block can have multiple exception handlers, as it is visible in the example below.<ref>{{Cite book|title = The C++ Programming Language|last = Stroustrup|first = Bjarne|publisher = Addison Wesley|year = 2013|isbn = 9780321563842|location = |pages = 344, 370}}</ref>
<!--"#include <iostream.h> is deprecated"-->
<!--"#include <iostream.h> is deprecated"-->
<source lang="cpp" line="1">
<syntaxhighlight lang="cpp" line="1">
#include <iostream>
#include <iostream>
#include <vector>
#include <vector>
Line 352: Line 435:
     }
     }
}
}
</source>
</syntaxhighlight>


It is also possible to raise exceptions purposefully, using the <syntaxhighlight lang="C++" inline>throw</syntaxhighlight> keyword; these exceptions are handled in the usual way. In some cases, exceptions cannot be used due to technical reasons. One such example is a critical component of an embedded system, where every operation must be guaranteed to complete within a specified amount of time. This cannot be determined with exceptions as no tools exist to determine the maximum time required for an exception to be handled.<ref>{{Cite book|title = The C++ Programming Language|last = Stroustrup|first = Bjarne|publisher = Addison Wesley|year = 2013|isbn = 9780321563842|location = |pages = 349}}</ref>
It is also possible to raise exceptions purposefully, using the <syntaxhighlight lang="C++" inline>throw</syntaxhighlight> keyword; these exceptions are handled in the usual way. In some cases, exceptions cannot be used due to technical reasons. One such example is a critical component of an embedded system, where every operation must be guaranteed to complete within a specified amount of time. This cannot be determined with exceptions as no tools exist to determine the maximum time required for an exception to be handled.<ref>{{Cite book|title = The C++ Programming Language|last = Stroustrup|first = Bjarne|publisher = Addison Wesley|year = 2013|isbn = 9780321563842|location = |pages = 349}}</ref>
Unlike [[Signal handler|signal handling]], in which the handling function is called from the point of failure, exception handling exits the current scope before the catch block is entered, which may be located in the current function or any of the previous function calls currently on the stack.


== Standard library ==
== Standard library ==
{{Main article|C++ Standard Library}}
[[Image:ANSI ISO C++ WP.jpg|thumb|right|The draft "Working Paper" standard that became approved as C++98; half of its size was devoted to the C++ Standard Library]]
The C++ [[standardization|standard]] consists of two parts: the core language and the standard library. C++ programmers expect the latter on every major implementation of C++; it includes aggregate types ([[sequence container (C++)#Vector|vectors]], lists, maps, sets, queues, stacks, arrays, tuples), [[algorithm]]s (find, for_each, binary_search, random_shuffle, etc.), input/output facilities ([[iostream]], for reading from and writing to the console and files), filesystem library, localisation support, [[smart pointers]] for automatic memory management, [[regular expression]] support, [[multithreading (software)|multi-threading]] library, atomics support (allowing a variable to be read or written to by 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++ [[exception handling|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).
{{Main|C++ Standard Library}}
The C++ [[standardization|standard]] consists of two parts: the core language and the standard library. C++ programmers expect the latter on every major implementation of C++; it includes aggregate types ([[sequence container (C++)#Vector|vectors]], lists, maps, sets, queues, stacks, arrays, tuples), [[algorithm]]s (find, [[Foreach loop|for_each]], [[Binary search algorithm|binary_search]], random_shuffle, etc.), input/output facilities ([[iostream]], for reading from and writing to the console and files), filesystem library, localisation support, [[smart pointers]] for automatic memory management, [[regular expression]] support, [[multithreading (software)|multi-threading]] library, atomics support (allowing a variable to be read or written to by 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++ [[exception handling|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 [[container (data structure)|container]]s as the collections of objects (such as [[array data structure|vector]]s and [[linked list|lists]]), [[iterator]]s that provide array-like access to containers, and [[algorithm]]s that perform operations such as searching and sorting.
A large part of the C++ library is based on the [[Standard Template Library]] (STL). Useful tools provided by the STL include [[container (data structure)|container]]s as the collections of objects (such as [[array data structure|vector]]s and [[linked list|lists]]), [[iterator]]s that provide array-like access to containers, and [[algorithm]]s that perform operations such as searching and sorting.
Line 367: Line 453:


Most C++ compilers, and all major ones, provide a standards-conforming implementation of the C++ standard library.
Most C++ compilers, and all major ones, provide a standards-conforming implementation of the C++ standard library.
== C++ Core Guidelines ==
The C++ Core Guidelines<ref>{{cite web|url=https://isocpp.github.io/CppCoreGuidelines|title=C++ Core Guidelines}}</ref> are an initiative led by Bjarne Stroustrup, the inventor of C++, and Herb Sutter, the convener and chair of the C++ ISO Working Group, to help programmers write 'Modern C++' by using best practices for the language standards C++14 and newer.
The main aim is to efficiently and consistently write type and resource safe C++.
The Core Guidelines were announced<ref>{{cite web|url=https://isocpp.org/blog/2015/09/bjarne-stroustrup-announces-cpp-core-guidelines|title=Bjarne Stroustrup announces C++ Core Guidelines}}</ref> in the opening keynote at CPPCon 2015.
The Guidelines are accompanied by the Guideline Support Library (GSL),<ref>{{cite web|url=https://github.com/Microsoft/GSL|title=Guidelines Support Library}}</ref> a header only library of types and functions to implement the Core Guidelines and static checker tools for enforcing Guideline rules.<ref>{{cite web|url=https://docs.microsoft.com/en-us/cpp/code-quality/using-the-cpp-core-guidelines-checkers?view=vs-2019|title=Use the C++ Core Guidelines checkers}}</ref>


== Compatibility ==
== Compatibility ==
Line 372: Line 467:


=== With C ===
=== With C ===
[[Image:C slash cpp.svg|thumb|right|upright=0.6|The relationship of C++ to C has always been a bit problematic]]
{{Details|Compatibility of C and C++}}
{{Details|Compatibility of C and C++}}


Line 381: Line 477:


== Criticism ==
== Criticism ==
{{Main article|Criticism of C++}}
{{Main|Criticism of C++}}


Despite its widespread adoption, some notable programmers have criticized the C++ language, including [[Linus Torvalds]],<ref name=torvalds>{{cite mailing list |url=https://lwn.net/Articles/249460/ |title=Re: [RFC] Convert builin-mailinfo.c to use The Better String Library |date=6 September 2007 |accessdate=31 March 2015 }}</ref> [[Richard Stallman]],<ref>{{cite mailing list |url=http://harmful.cat-v.org/software/c++/rms |title=Re: Efforts to attract more users? |date=12 July 2010 |accessdate=31 March 2015 }}</ref> [[Joshua Bloch]], [[Ken Thompson]],<ref>{{cite web |url=https://www.drdobbs.com/open-source/interview-with-ken-thompson/229502480 |title=Dr. Dobb's: Interview with Ken Thompson |author=Andrew Binstock |date=18 May 2011 |accessdate=7 February 2014}}</ref><ref name="Seibel2009">{{cite book|author=Peter Seibel|title=Coders at Work: Reflections on the Craft of Programming|url=https://books.google.com/books?id=nneBa6-mWfgC&pg=PA475|date=16 September 2009|publisher=Apress|isbn=978-1-4302-1948-4|pages=475–476}}</ref><ref name="gigamonkeysWordpress">https://gigamonkeys.wordpress.com/2009/10/16/coders-c-plus-plus/</ref> and [[Donald Knuth]].<ref name="dobbsKnuth">https://www.drdobbs.com/architecture-and-design/an-interview-with-donald-knuth/228700500</ref><ref name="knuth1993">http://tex.loria.fr/litte/knuth-interview</ref>
Despite its widespread adoption, some notable programmers have criticized the C++ language, including [[Linus Torvalds]],<ref name=torvalds>{{cite mailing list |url=https://lwn.net/Articles/249460/ |title=Re: [RFC] Convert builin-mailinfo.c to use The Better String Library |date=6 September 2007 |accessdate=31 March 2015 }}</ref> [[Richard Stallman]],<ref>{{cite mailing list |url=http://harmful.cat-v.org/software/c++/rms |title=Re: Efforts to attract more users? |date=12 July 2010 |accessdate=31 March 2015 }}</ref> [[Joshua Bloch]], [[Ken Thompson]],<ref>{{cite web |url=https://www.drdobbs.com/open-source/interview-with-ken-thompson/229502480 |title=Dr. Dobb's: Interview with Ken Thompson |author=Andrew Binstock |date=18 May 2011 |accessdate=7 February 2014}}</ref><ref name="Seibel2009">{{cite book|author=Peter Seibel|title=Coders at Work: Reflections on the Craft of Programming|url=https://books.google.com/books?id=nneBa6-mWfgC&pg=PA475|date=16 September 2009|publisher=Apress|isbn=978-1-4302-1948-4|pages=475–476}}</ref><ref name="gigamonkeysWordpress">https://gigamonkeys.wordpress.com/2009/10/16/coders-c-plus-plus/</ref> and [[Donald Knuth]].<ref name="dobbsKnuth">https://www.drdobbs.com/architecture-and-design/an-interview-with-donald-knuth/228700500</ref><ref name="knuth1993">http://tex.loria.fr/litte/knuth-interview</ref>


One of the most often criticised points of C++ is its perceived complexity as a language, with the criticism that a large number of non-orthogonal features in practice necessitates restricting code to subset of C++, thus eschewing the readability benefits of common style and idioms. As expressed by [[Joshua Bloch]]: <blockquote> I think C++ was pushed well beyond its complexity threshold and yet there are a lot of people programming it. But what you do is you force people to subset it. So almost every shop that I know of that uses C++ says, “Yes, we’re using C++ but we’re not doing multiple-implementation inheritance and we’re not using operator overloading.” There are just a bunch of features that you’re not going to use because the complexity of the resulting code is too high. And I don’t think it’s good when you have to start doing that. You lose this programmer portability where everyone can read everyone else’s code, which I think is such a good thing. </blockquote>  
One of the most often criticised points of C++ is its perceived complexity as a language, with the criticism that a large number of non-orthogonal features in practice necessitates restricting code to subset of C++, thus eschewing the readability benefits of common style and idioms. As expressed by [[Joshua Bloch]]: <blockquote> I think C++ was pushed well beyond its complexity threshold, and yet there are a lot of people programming it. But what you do is you force people to subset it. So almost every shop that I know of that uses C++ says, “Yes, we’re using C++ but we’re not doing multiple-implementation inheritance and we’re not using operator overloading.” There are just a bunch of features that you’re not going to use because the complexity of the resulting code is too high. And I don’t think it’s good when you have to start doing that. You lose this programmer portability where everyone can read everyone else’s code, which I think is such a good thing. </blockquote>


[[Donald Knuth]] (1993, commenting on pre-standardized C++), who said of [[Edsger Dijkstra]] that "to think of programming in C++" "would make him physically ill":<ref name="dobbsKnuth" /><ref name="knuth1993" /> <blockquote> The problem that I have with them today is that... C++ is too complicated. At the moment, it's impossible for me to write portable code that I believe would work on lots of different systems, unless I avoid all exotic features. Whenever the C++ language designers had two competing ideas as to how they should solve some problem, they said "OK, we'll do them both". So the language is too baroque for my taste. </blockquote>
[[Donald Knuth]] (1993, commenting on pre-standardized C++), who said of [[Edsger Dijkstra]] that "to think of programming in C++" "would make him physically ill":<ref name="dobbsKnuth" /><ref name="knuth1993" /> <blockquote> The problem that I have with them today is that... C++ is too complicated. At the moment, it's impossible for me to write portable code that I believe would work on lots of different systems, unless I avoid all exotic features. Whenever the C++ language designers had two competing ideas as to how they should solve some problem, they said "OK, we'll do them both". So the language is too baroque for my taste. </blockquote>
Line 392: Line 488:
Stroustrup campaigned for years and years and years, way beyond any sort of technical contributions he made to the language, to get it adopted and used. And he sort of ran all the standards committees with a whip and a chair. And he said “no” to no one. He put every feature in that language that ever existed. It wasn’t cleanly designed—it was just the union of everything that came along. And I think it suffered drastically from that. </blockquote>
Stroustrup campaigned for years and years and years, way beyond any sort of technical contributions he made to the language, to get it adopted and used. And he sort of ran all the standards committees with a whip and a chair. And he said “no” to no one. He put every feature in that language that ever existed. It wasn’t cleanly designed—it was just the union of everything that came along. And I think it suffered drastically from that. </blockquote>


However [[Brian Kernighan]], also a colleague at Bell Labs, disputes this assessment:<ref>{{cite video|people=Brian Kernighan|date=July 18, 2018|title=Brian Kernighan Q&A - Computerphile|url=https://www.youtube.com/watch?v=zmYhR8cUX90&t=5m17s}}</ref> <blockquote>C++ has been enormously influential. ... Lots of people say C++ is too big and too complicated etc. etc. but in fact it is a very powerful language and pretty much everything that is in there is there for a really sound reason: it is not somebody doing random invention, it is actually people trying to solve real world problems. Now a lot of the programs that we take for granted today, that we just use, are C++ programs. </blockquote>  
However [[Brian Kernighan]], also a colleague at Bell Labs, disputes this assessment:<ref>{{cite video|people=Brian Kernighan|date=July 18, 2018|title=Brian Kernighan Q&A - Computerphile|url=https://www.youtube.com/watch?v=zmYhR8cUX90&t=5m17s}}</ref> <blockquote>C++ has been enormously influential. ... Lots of people say C++ is too big and too complicated etc. etc. but in fact it is a very powerful language and pretty much everything that is in there is there for a really sound reason: it is not somebody doing random invention, it is actually people trying to solve real world problems. Now a lot of the programs that we take for granted today, that we just use, are C++ programs. </blockquote>


Stroustrup himself comments that C++ semantics are much cleaner than its syntax: "within C++, there is a much smaller and cleaner language struggling to get out".<ref>http://www.stroustrup.com/bs_faq.html#really-say-that</ref>
Stroustrup himself comments that C++ semantics are much cleaner than its syntax: "within C++, there is a much smaller and cleaner language struggling to get out".<ref>http://www.stroustrup.com/bs_faq.html#really-say-that</ref>


Other complaints may include a lack of [[reflection (computer programming)|reflection]] or [[garbage collection (computer science)|garbage collection]], slow compilation times, perceived [[feature creep]],<ref>{{cite web |url=https://commandcenter.blogspot.mx/2012/06/less-is-exponentially-more.html |title=Less is exponentially more |year=2012 |last=Pike |first=Rob}}</ref> and verbose error messages, particularly from template metaprogramming.<ref>{{cite web|url=https://yosefk.com/c++fqa/defective.html|title=Defective C++|first=Yossi|last=Kreinin|date=13 October 2009|accessdate=3 February 2016}}</ref>
Other complaints may include a lack of [[reflection (computer programming)|reflection]] or [[garbage collection (computer science)|garbage collection]], long compilation times, perceived [[feature creep]],<ref>{{cite web |url=https://commandcenter.blogspot.mx/2012/06/less-is-exponentially-more.html |title=Less is exponentially more |year=2012 |last=Pike |first=Rob}}</ref> and verbose error messages, particularly from template metaprogramming.<ref>{{cite web|url=https://yosefk.com/c++fqa/defective.html|title=Defective C++|first=Yossi|last=Kreinin|date=13 October 2009|accessdate=3 February 2016}}</ref>


== See also ==
== See also ==
{{Portal|Computer programming|C++}}
* [[Comparison of programming languages]]
* [[Comparison of programming languages]]
* [[List of C++ compilers]]
* [[List of C++ compilers]]
* [[Outline of C++]]
* [[Outline of C++]]
* [[:Category:C++ libraries|C++ Libraries (category)]]
* [[:Category:C++ libraries|C++ Libraries (category)]]
* [[C language]]
* [[Assembly language]]
* [[Python]]
:* [[Machine Learning Mastery with Python]]


== References ==
== References ==
{{Reflist|30em}}
<references />
 
== Further reading ==
{{Refbegin|30em}}
* {{Cite book |first=David |last=Abrahams |authorlink=David Abrahams (computer programmer) |first2=Aleksey |last2=Gurtovoy  |title=C++ Template Metaprogramming: Concepts, Tools, and Techniques from Boost and Beyond |publisher=Addison-Wesley |isbn=0-321-22725-5 }}
* {{Cite book |first=Andrei |last=Alexandrescu |authorlink=Andrei Alexandrescu |year=2001 |title=Modern C++ Design: Generic Programming and Design Patterns Applied |publisher=Addison-Wesley |isbn=0-201-70431-5 }}
* {{Cite book |first=Andrei |last=Alexandrescu |authorlink=Andrei Alexandrescu |first2=Herb |last2=Sutter |authorlink2=Herb Sutter|year=2004 |title=C++ Design and Coding Standards: Rules and Guidelines for Writing Programs |publisher=Addison-Wesley |isbn=0-321-11358-6 }}
* {{Cite book |first=Pete |last=Becker |authorlink=Pete Becker |year=2006 |title=The C++ Standard Library Extensions : A Tutorial and Reference |publisher=Addison-Wesley |isbn=0-321-41299-0 }}
* {{Cite book |first=Frank |last=Brokken |year=2010 |title=C++ Annotations |publisher=University of Groningen |isbn=90-367-0470-7 |url=http://www.icce.rug.nl/documents/cplusplus/ }}
* {{Cite book |first=James O. |last=Coplien |authorlink=James O. Coplien |origyear=reprinted with corrections, original year of publication 1992|date=1994 |title=Advanced C++: Programming Styles and Idioms |isbn=0-201-54855-0 }}
* {{Cite book |first=Stephen C. |last=Dewhurst |year=2005 |title=C++ Common Knowledge: Essential Intermediate Programming |publisher=Addison-Wesley |isbn=0-321-32192-8 }}
* {{Cite book |author=Information Technology Industry Council |authorlink=Information and Communications Technology Council |publisher=ISO/IEC |location=Geneva |title=Programming languages&nbsp;– C++ |id=14882:2003(E) |edition=Second |date=15 October 2003 }}
* {{Cite book |first=Nicolai M. |last=Josuttis |title=The C++ Standard Library, A Tutorial and Reference |edition=Second|year=2012 |publisher=Addison-Wesley |isbn=0-321-62321-5}}
* {{Cite book |first=Andrew |last=Koenig |authorlink=Andrew Koenig (programmer) |first2=Barbara E. |last2=Moo |year=2000 |title=Accelerated C++ – Practical Programming by Example |publisher=Addison-Wesley |isbn=0-201-70353-X }}
* {{Cite book |first=Stanley B. |last=Lippman |authorlink=Stanley B. Lippman |first2=Josée |last2=Lajoie |first3=Barbara E. |last3=Moo |year=2011|edition=Fifth |title=C++ Primer |publisher=Addison-Wesley |isbn= 0-321-71411-3}}
* {{Cite book |first=Stanley B. |last=Lippman |year=1996 |title=Inside the C++ Object Model |publisher=Addison-Wesley |isbn=0-201-83454-5 }}
* {{Cite book |first=Scott |last=Meyers |authorlink=Scott Meyers |year=2005 |title=Effective C++ |edition=Third |publisher=Addison-Wesley |isbn=0-321-33487-6 }}
* {{Cite book |first=Bjarne |last=Stroustrup|authorlink=Bjarne Stroustrup |year=2013 |title=The C++ Programming Language |edition=Fourth |publisher=Addison-Wesley |isbn=978-0-321-56384-2 }}
* {{Cite book |first=Bjarne |last=Stroustrup|authorlink=Bjarne Stroustrup |year=1994 |title=The Design and Evolution of C++ |publisher=Addison-Wesley |isbn=0-201-54330-3 }}
* {{Cite book |first=Bjarne |last=Stroustrup|authorlink=Bjarne Stroustrup|year=2014 |title=Programming Principles and Practice Using C++ |edition=Second |publisher=Addison-Wesley |isbn=978-0-321-99278-9 }}
* {{Cite book |first=Herb |last=Sutter|authorlink=Herb Sutter |year=2001 |title=More Exceptional C++: 40 New Engineering Puzzles, Programming Problems, and Solutions |publisher=Addison-Wesley |isbn=0-201-70434-X }}
* {{Cite book |first=Herb |last=Sutter|authorlink=Herb Sutter |year=2004 |title=Exceptional C++ Style |publisher=Addison-Wesley |isbn=0-201-76042-8 }}
* {{Cite book |first=David |last=Vandevoorde |first2=Nicolai M. |last2=Josuttis |year=2003 |title=C++ Templates: The complete Guide |publisher=Addison-Wesley |isbn=0-201-73484-2 }}
{{refend}}


== External links ==
== External links ==
{{Sister project links|n=no|s=no|b=Subject:C++ programming language}}
* [http://www.open-std.org/jtc1/sc22/wg21/ JTC1/SC22/WG21]{{snd}} the ISO/IEC C++ Standard Working Group
* [http://www.open-std.org/jtc1/sc22/wg21/ JTC1/SC22/WG21]{{snd}} the ISO/IEC C++ Standard Working Group
* [https://isocpp.org/ Standard C++ Foundation]{{snd}} a non-profit organization that promotes the use and understanding of standard C++. Bjarne Stroustrup is a director of the organization.
* [https://isocpp.org/ Standard C++ Foundation]{{snd}} a non-profit organization that promotes the use and understanding of standard C++. Bjarne Stroustrup is a director of the organization.


{{ISO standards}}
{{Programming languages}}
{{C++ programming language}}
{{List of International Electrotechnical Commission standards}}
{{Authority control}}
{{DEFAULTSORT:C}}
[[Category:Algol programming language family]]
[[Category:Algol programming language family]]
[[Category:C++| ]]
[[Category:C++| ]]
23

edits

Navigation menu