C++
| : |
: -, , , |
|---|---|
| : | |
| : | |
| (): | |
| : |
.c++ .cpp .cxx .cc .h++ .hpp .hxx .hh .h |
| : | |
| : |
GNU C++, Microsoft Visual C++, Intel C++ compiler, Clang, Comeau C/C++, Embarcadero (Borland) C++ Builder, Watcom C++ compiler, Digital Mars C++, Oracle Solaris Studio C++ compiler, Turbo C++ |
| : |
ISO/IEC 14882 C++ |
, , , , , (), , - , , , , [1][2]. C, - .[2] «C++» C, ++ .
,[3][4] C++ . , , , , , (, ). C++ , . GNU, Microsoft, Intel Embarcadero (Borland). C++ , Java C#.
C++ C. , C, C++, , C++ C.
|
|
[]
| [5] | |
|---|---|
| BCPL | 1966 |
| ( UNIX) | 1969 |
| ( ) | 1973 |
| 1979 | |
| C84 | 1984 |
| Cfront ( E) | 1984 |
| Cfront ( 1.0) | 1985 |
| / | 1988 |
| () | 1991 |
| ANSI C++ / ISO-C++ | 1996 |
| ISO/IEC 14882:1998 | 1998 |
| ISO/IEC 14882:2003 | 2003 |
| C++/CLI | 2005 |
| TR1 | 2005 |
| C++11 | 2011 |
1980- , Bell Laboratories C . . 1998 C++: ISO/IEC 14882:1998 «Standard for the C++ Programming Language»; 2003 ISO/IEC 14882:2003.[6]
, «C », 1980 .[7] . , Simula , , . BCPL , . Bell Labs ( ). . , C ( BCPL) , . C, UNIX, Bell, , . . , ( - ) ( C). C ( ), , , inline- .
C ( C++), cfront , C C. , , , .
1983 C C++. , , , , , , , (//). 1985 . 1985 « C++», , - . 1989 C++ 2.0. , , -, - .
1990 « C++», . , , , .
C++ . C++ /, C printf scanf. .
C++, . ( ) .
[]
1998 ISO/IEC 14882:1998 ( C++98),[8] C++ (ISO/IEC JTC1/SC22/WG21 working group).
2003 ISO/IEC 14882:2003, .
2005 «Library Technical Report 1» ( TR1). , , , , C++. TR1 C++.
2009 , C++99, C++0x, C++11, , TR1.
[]
, , C ++ ( ). C+ , C , , . B, « C C».[7]
[] C++
- , C.
- , , , - .
- , .
- C, C.
- C C++: , , .
- , .
- , .
- .
[]
C++ 2003 : .
, C++, . C++ C.
C++, , , . , , . - cfront. -. - , C++ .
[] -
, - (), , , .
[]
++ , C
/*
,
*/
,
//
, // , , \ ( ??/), .
[]
C++ :
- :
char,wchar_t. - :
signed char,short int,int,long int(long long int, C++11). - :
unsigned char,unsigned short int,unsigned int,unsigned long int(unsigned long long int, C++11). - :
float,double,long double. - :
bool,truefalse.
bool. if, while bool.[10]
. , void f(int &x) {x=3;} 3. , . , {double &b=a[3]; b=sin(b);} a[3]=sin(a[3]);. , : ; ; , , . . , , , ; , , .
[]
-
inlineinline-. , , inline . inline- , , , . inline-, , , ,inline. , inline- , ( inline- , ), , inline, . :
inline double Sqr(double x) {return x*x;}.
struct Time { int hh, mm, ss; }; Time t1, t2;
namespace Foo { const int x=5; typedef int** T; void f(int y) {return y*x}; double g(T); ... }
T, x, f, g Foo::T, Foo::x, Foo::f Foo::g . - ,
using namespace Foo;
using Foo::T;
, , , .
namespace { ... }
, , .
- . ,
void f(int x, int y=5, int z=10),f(1),f(1,5)f(1,5,10). - , C, , , . , , ,
int printf(const char* fmt, ...). - ,
typedef, , . , :
struct S { typedef int** T; T x; }; S::T y;
void Print(int x); void Print(double x); void Print(int x, int y);
- . , :
struct Date {int day, month, year;}; void operator ++(struct Date& date);
() . new, new[], delete delete[], (, int); , C++ (, **); , , (, a+b*c , , a, b c). [] ( ) () ( ).
- (
template). ,template<class T> T Min(T x, T y) {return x<y?x:y;}Min . , . ,template<class T> struct Array{int len; T* val;};,Array<float> x; -
mallocfreeoperator new,operator new[],operator deleteoperator delete[],new,new[],deletedelete[]. T , , X A n , X,
delete , NULL, . non-POD new- ; delete- (. ).
[] -
C++ (class) , class, struct union, (structure) , struct, (union) , union.
[]
, (. Alloc . (inline))
[] -
- ( ) const
class Array { ... inline double operator[] (int n) const;
( , mutable). , .
[]
, -, . .
, ( ):
| / | private- | protected- | public- |
|---|---|---|---|
| private- | private | private | |
| protected- | protected | protected | |
| public- | protected | public |
, , , , , .
[]
class Figure { ... void Draw() const; ... }; class Square : public Figure { ... void Draw() const; ... }; class Circle : public Figure { ... void Draw() const; ... };
Figure::Draw(), Square::Draw() Circle::Draw() . :
Circle *c = new Circle(0,0,5); Figure *f = c; // ok: Figure Circle c->Draw(); f->Draw(); // , f , c
, Circle, c Circle::Draw(), f Figure::Draw(), f Figure. .
C++ , . - .
class Figure { ... virtual void Draw() const; ... }; class Square : public Figure { ... void Draw() const; ... }; class Circle : public Figure { ... void Draw() const; ... }; Figure * figures[10]; figures[0] = new Square(1, 2, 10); figures[1] = new Circle(3, 5, 8); ... for (int i = 0; i < 10; i++) figures[i]->Draw();
Square::Draw() Circle::Draw() .
-, = 0:
class Figure { ... virtual void Draw() const = 0; );
, , .
[]
C++ . (struct) C, , (class) C++ , - (member functions). ++ : (, public), (protected) (, , private). C++ , , .
| private | protected | public | |
|---|---|---|---|
, .
, ( , !):
class Array { public: Array() : len(0), val(NULL) {} Array(int _len) : len(_len) { val = new double[_len]; } Array(const Array & a); ~Array() { Free(); } inline const double & Elem(int i) const { return val[i]; } inline void ChangeElem(int i, double x) { val[i] = x; } protected: void Alloc(int _len) { if (len == 0) Free(); len = _len; val = new double[len]; } void Free() { delete [] val; len = 0; } int len; double * val; };
Array 2 -, 2 , 3 . inline , , .
[]
- , - . friend. :
class Matrix { ... friend Matrix Multiply(Matrix m1, Matrix m2); ... }; Matrix Multiply(Matrix m1, Matrix m2) { ... }
Multiply - Matrix.
-. A B, ( ) - B. :
class Matrix { ... friend class Vector; ... };
C++ « ».
C++ ( ). C++0x . VC++, GNU C++ Comeau C++ , C++0x.
[]
( ) , . , .
(, Array::Array), , (, Array::~Array). . . ( ), , ( ) .
, , , - (, Array::Array(const Array&)) ( ), , , , :
Array a(5); // Array::Array(int) Array b; // Array::Array() Array c(a); // Array::Array(const Array&) Array d=a; // Array::Array(const Array&) b=c; // = // ( ), , // -. //
, . , . , .
[]
- :
class Array { ... inline double& operator[] (int n) { return val[n]; }
Array a(10); ... double b = a[5];
[]
++ , ++, , , C , C++. C++ C 1990 , C. C++ ( #include) . C++ 50 (, <cstddef> , <new> . .).
void* operator new(std::size_t) throw(std::bad_alloc); void* operator new[](std::size_t) throw(std::bad_alloc); void operator delete(void*) throw(); void operator delete[](void*) throw();
- .
[]
STL C++ , HP, SGI. «STL», , , ( / (iostream), C ).
STLport[11], SGI STL, STL, IOstream . .
[] ++ C
[] C
C++ C :
C++ , , new delete, bool, , , , , , , ( , , -, , ), , , ::, , . C++ , C.
C++ (//), C BCPL.
C++ C, , const inline, for C++ (//). C , C++, va_arg -.
[] C++ C
, C C++, C++ C . C , C++. Objective C, C , C.
. , C++ main() , C . , C++ ; , , .
, , , , . , «», C, «C++» C++. - , C (, 'a') int, C++ char, .
#include <stdio.h> int main() { printf("%s\n", (sizeof('a') == sizeof(char)) ? "C++" : "C"); return 0; }
[]
ISO/IEC 14882:2003(E) 2003 . C++03. C++11.
C++ , . , C++ C++ Boost. , .
[] export
export, .
, export , Comeau C++ 2003 ( 5 C++98). 2004 - Borland C++ Builder X .
- EDG. , Microsoft Visual C++ GCC (GCC 3.4.4), . , C++, export , . export: Microsoft Visual C++ 7.0, GCC 3.4.4, Microsoft Visual Studio 2010 .
, , , C++.
[] C++
[] № 1
int main() { return 0; }
C++ , main() int. , main(), C++.
C++ .
[] № 2
, .
int main(){}
C++ ( C), main(), return 0;. main().
[] № 3
Hello World, , , .
#include <iostream> // std::cout std::endl << int main() { std::cout << "Hello, world!" << std::endl; return 0; }
[] № 4
C++ . (STL).
#include <iostream> // std::cout #include <vector> // std::vector<> #include <map> // std::map<> std::pair<> #include <algorithm> // std::for_each() #include <string> // std::string using namespace std; // "std" void display_item_count(pair < string const, vector<string> > const& person) { // person - : person.first - , // person.second - ( ) cout << person.first << " is carrying " << person.second.size() << " items" << endl; } int main() { // map< string, vector<string> > items; // items["Anya"].push_back("scarf"); items["Dmitry"].push_back("tickets"); items["Anya"].push_back("puppy"); // for_each(items.begin(), items.end(), display_item_count); }
, , :
#include <vector> int main() { using std::vector; vector<int> my_vector; }
, ( ). , , .
[] № 5
boost . . STL- .
#include <iostream> #include <numeric> #include <boost/iterator/counting_iterator.hpp> #include <boost/iterator/transform_iterator.hpp> int odd(int i) { return 2 * i + 1; } int square(int i) { return i * i; } typedef boost::counting_iterator <int> counter; typedef boost::transform_iterator <int (*)(int), counter> transformer; transformer odds(int n) { return transformer(counter(n), odd); } transformer squares(int n) { return transformer(counter(n), square); } int main() { using namespace std; cout << "Enter vector length: "; int n; cin >> n; cout << inner_product( odds(0), odds(n), squares(0), 0 ) << endl; }
«» . , STL , . , , ++, inner_product(), , . inner_product : « n».
[]
, , , , C++ , , , .
[]
C++ , , . :
- , , , , (, ).
- . , (, ), . , . .
- , , . ( ) (, , . .), , (, ).
- - .
- (const) (mutable) . , , , . , , . - ( , ). mutable .
- , , .
- , . , Boost.Bind .
- - . , Boost.Spirit, EBNF- C++.
- - . Loki, SmartPtr , , 300 « » .
- : . (,
std::numeric_limits <T>). , C++ . - . , . , , .
- , .
- C, C- ( C C++; , C, C++ - , , , C, , ++).
[]
C++ . , :
- , C, .
- , .
- , .
- .
[]
-
=,==. , , , , . :. , , x , x ,if (x=0) { }
if. «», . , . - (
=), (++), (--) . , , . C , . , C C++ , «» . - . , .
- ++ , C, ++. . ,
dynamic_cast. , grep. C .
[]
[]
- , C, . , ( ) , , , . (, Lisp Nemerle) ( , C/C++).
- ( , C , ). (
#include) ( , , ). C++. . - C++ . C++ , . , . [15] Lisp/Scheme, Nemerle . , D , .
- C++0x. (Loki, Boost), (, / ), . , , .
- C++ . , C++ [16]. , RAII . ++ .
[]
[]
, ++ :
- C , , C.
- ++ . .
- , ++ , , ++. ++ , , . , .
[] C++ Java
. : (.) Comparison of Java and C++
C++ C, . , C++ , , C[?]. , , C++.
C++ -, Java. C++, Java , - , , , . Microsoft C#, C++ , Java. Nemerle, C# . C++ Java C# D, .
Java C++ - C, , , . (, Java, C# Nemerle, ).
- C++ C, . Java C C++, , . Java ++. , Java , , .
- Java- , , C++ (, , C++ ). : Java , . Java , ( -) . Java , - , ( ). .
- C++ « » (RAII), (,
std::vectorstd::ifstream). , , ( , . .), . Java , , , . , , RAII , . Java , , Java . , , , Java . - Java -, , , , . C++ . , . . , .
- C++ . Java . , . , C++ ( , , ), . , Java .
- ++, Java - , . Java , static [23]. Java [24].
- C++ RTTI . Java . C++, CTTI.
- C++ , , , , , , [25]. , , , . . , C++ (, , ) , . Java , , .
, . , Java Java, C++ . C++, , , (, ).
. , Java C++ , . , .
[] .
| C++ ? |
[]
- Herbert Schildt C++ The Complete Reference Third Edition. Osborne McGraw-Hill. ISBN 978-0078824760
- 1 2 . . 2.1. C++? // C++. . . . 57.
- Programming Language Popularity (2009). 27 2012. 16 2009.
- TIOBE Programming Community Index (2009). 27 2012. 6 2009.
- , Pure C++: Hello, C++/CLI (.)
- C++ Standards
- 1 2 . . 1.4. // C++. . . . 46.
- Stroustrup, Bjarne C++ Glossary. 27 2012. 8 2007.
- . C++ = The Design and Evolution of C++. .: , 2007. 445 . ISBN 5-469-01217-4
- ISO/IEC 14882:1998, 6.4, 4: «The value of a condition that is an initialized declaration in a statement other than a
switchstatement is the value of the declared variable implicitly converted toboolThe value of a condition that is an expression is the value of the expression, implicitly converted toboolfor statements other thanswitch; if that conversion is ill-formed, the program is ill-formed». - STLport: Welcome!
- The Java Tutorials: The switch Statement
- MSDN: The switch statement in C#
- , . // : C++ = Programming: Principles and Practice Using C++. .: «. . », 2001. . 1065, 1066, 1133. 1248 . ISBN 978-5-8459-1621-1
- TIOBE Programming Community Index for January 2010
- Boehm-Demers-Weiser garbage collector for C and C++
- Dave Gottner. Templates Without Code Bloat // Dr. Dobb's Journal. 1995.
- Adrian Stone. Minimizing Code Bloat: Redundant Template Instantiation. Game Angst (22 2009). 27 2012. 19 2010.
- Herb Sutter. C++ Conformance Roundup // Dr. Dobb's Journal. 2001.
- Are there any compilers that implement all of this?. comp.std.c++ frequently asked questions / The C++ language. Comeau Computing (.) (10 2008). 27 2012. 19 2010.
- vanDooren. C++ keyword of the day: export. Blogs@MSMVPs (24 2008). «The export keyword is a bit like the Higgs boson of C++. Theoretically it exists, it is described by the standard, and noone has seen it in the wild. There is 1 C++ compiler front-end in the world which actually supports it» 27 2012. 19 2010.
- Scott Meyers. Code Bloat due to Templates. comp.lang.c++.moderated. Usenet (16 2002). 19 2010.
- Class Arrays, JavaTM 2 Platform Std. Ed. v1.4.2
- The Java Tutorials. A Closer Look at the «Hello World!» Application
- From "C++ Template Metaprogramming, " by David Abrahams and Aleksey Gurtovoy. Copyright (c) 2005 by Pearson
[]
- . : C++, = Programming: Principles and Practice Using C++. .: «», 2011. . 1248. ISBN 978-5-8459-1705-8
- . C++ (C++11). , 6- = C++ Primer Plus, 6th Edition (Developer's Library). .: «», 2012. 1248 . ISBN 978-5-8459-1778-2
- . Visual C++ 2010: = Ivor Horton's Beginning Visual C++ 2010. .: «», 2010. . 1216. ISBN 978-5-8459-1698-3
- . . C++ = The C++ Programming Language / . . 3- . .; .: , 1999. 991 . 3000 . ISBN 5-7940-0031-7 ( ), ISBN 5-7989-0127-0 (), ISBN 0-201-88954-4 (.)
- . C++. = The C++ programming language. Special edition. .: -, 2007. 1104 . ISBN 5-7989-0223-4
- . C++, 4- = C++: The Complete Reference, 4th Edition. .: «», 2011. . 800. ISBN 978-5-8459-0489-8
- . , . , . C++ STL: , 2- ( C++ in Depth) = STL Tutorial and Reference Guide: C++ Programming with the Standard Template Library, 2nd edition, (C++ in Depth Series). .: «», 2010. . 432. ISBN 978-5-8459-1665-5
- , . C++ 24 = Sams Teach Yourself C++ in 24 Hours, Complete Starter Kit. 4- . .: , 2007. 448 . ISBN 0-672-32681-7
- . . C++. . -, 2007. 624 . ISBN 5-91136-030-6
[]
- , C++
- . Techniques for scientific C++ (.)
- . C++0x (.)
- C++ (.) freecomputerbooks.com
- forum.vingrad.ru C++
- C++ (.)
- cpp, cpp.applied C++ C++ RSDN
- comp.lang.c++.moderated (.)
- ,
- TNT JAMA/C++ : Template Numerical Toolkit 1-, 2- 3- JAMA/C++ . .
- Blitz++ C++,
- The Matrix Template Library C++
- Boost C++ Libraries C++
- GNU Scientific Library C/C++
- VivaCore C/C++
| Borland Turbo C Clang GCC LCC Pelles C PCC TCC Visual C++ (C++/CLI C++/CX) Watcom C/C++ compiler | |
| glibc dietlibc uClibc Newlib Eglibc Bionic | |
| C- | |
| C++ C# D Objective-C Alef Limbo Go Vala | |
| C | C C++ ( ) Pascal C C - Java |

