The C++ language has two main components: a primary mapping of hardware features provided primarily by the C subset, and zero-overhead abstractions predicated on those mappings. Stroustrup describes C++ as "a light-weight abstraction program writing language for building and using efficient and elegant abstractions"; and "offering both hardware access and abstraction may be the basis of C++. Carrying it out efficiently is usually what distinguishes it from other languages."
Source: turbo c++
C++ inherits the majority of C's syntax. The next is usually Bjarne Stroustrup's version of the Hello world program that uses the C++ Standard Library stream facility to create a note to standard output:
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.
Static storage duration objects
Static storage duration objects are manufactured before main() is usually entered (see exceptions below) and destroyed backwards order of creation after main() exits. The precise order of creation isn't specified by the typical (though there are several rules defined below) to permit implementations some freedom in how exactly to organize their implementation. Even more formally, objects of the type possess a lifespan that "shall last throughout this program".
Static storage duration objects are initialized in two phases. First, "static initialization" is conducted, and only in the end static initialization is conducted, "dynamic initialization" is conducted. In static initialization, all objects are first initialized with zeros; from then on, all objects which have a constant initialization phase are initialized with the constant expression (i.e. variables initialized with a literal or constexpr). Though it isn't specified in the typical, the static initialization phase could be completed at compile period and saved in the info partition of the executable. Dynamic initialization involves all object initialization done with a constructor or function call (unless the function is definitely marked with constexpr, in C++11). The powerful initialization order is thought as the order of declaration within the compilation unit (i.e. the same file). No guarantees are given about the order of initialization between compilation units.
Thread storage duration objects
Variables of the type have become similar to static storage duration objects. The primary difference may be the creation time is merely ahead of thread creation and destruction is performed following the thread has been joined.
Automatic storage duration objects
The most typical variable types in C++ are local variables in the function or block, and temporary variables. The normal feature about automatic variables is they have a lifetime that's limited by the scope of the variable. They are manufactured and possibly initialized at the idea of declaration (observe below for details) and destroyed in the reverse order of creation when the scope is left. That is applied by allocation on the stack.
Local variables are manufactured as the idea of execution passes the declaration point. If the variable includes a constructor or initializer that is used to define the original state of the thing. Local variables are destroyed when the neighborhood block or function they are declared in is closed. C++ destructors for local variables are called by the end of the thing lifetime, allowing a discipline for automatic resource management termed RAII, which is trusted in C++.
Member variables are manufactured when the parent object is established. Array members are initialized from 0 to the last person in the array to be able. Member variables are destroyed when the parent object is destroyed in the reverse order of creation. i.e. If the parent can be an "automatic object" then it'll be destroyed when it is out of scope which triggers the destruction of most its members.
Temporary variables are manufactured as the consequence of expression evaluation and so are destroyed when the statement containing the expression has been fully evaluated (usually at the ; by the end of a statement).
コメント