Sunday, May 28, 2017

Explanation of C++ Language

Welcome Back to C++ (Modern C++Part-2


The C++ language itself has also evolved. Compare the following code snippets. This one shows how things used to be in C++:
C++
  
// circle and shape are user-defined types  
circle* p = new circle( 42 );   
vector<shape*> v = load_shapes();  
  
for( vector<circle*>::iterator i = v.begin(); i != v.end(); ++i ) {  
    if( *i && **i == *p )  
        cout << **i << “ is a match\n”;  
}  
  
for( vector<circle*>::iterator i = v.begin();  
        i != v.end(); ++i ) {  
    delete *i; // not exception safe  
}  
  
delete p;  
  

Here's how the same thing is accomplished in modern C++:
C++
  
#include <memory>  
#include <vector>  
// ...  
// circle and shape are user-defined types  
auto p = make_shared<circle>( 42 );  
vector<shared_ptr<shape>> v = load_shapes();  
  
for_each( begin(v), end(v), [&]( const shared_ptr<shape>& s ) {  
    if( s && *s == *p )  
        cout << *s << " is a match\n";  
} );  
  

In present day C++, you don't need to utilize new/erase or express exemption taking care of on the grounds that you can utilize keen pointers. When you utilize the auto sort conclusion and lambda work, you can compose code faster, fix it, and comprehend it better. Also, for_each is cleaner, less demanding to utilize, and less inclined to unintended blunders than a for circle. You can utilize standard together with insignificant lines of code to compose your application. Also, you can make that code special case safe and memory-safe, and have no portion/deallocation or blunder codes to manage. 
Present day C++ fuses two sorts of polymorphism: aggregate time, through layouts, and run-time, through legacy and virtualization. You can blend the two sorts of polymorphism to incredible impact. The STL format shared_ptr utilizes inside virtual strategies to finish its evidently easy sort eradication. In any case, don't over-utilize virtualization for polymorphism when a layout is the better decision. Layouts can be capable. 
In case you're coming to C++ from another dialect, particularly from an oversaw dialect in which the greater part of the sorts are reference sorts and not very many are esteem sorts, realize that C++ classes are esteem sorts as a matter of course. Yet, you can indicate them as reference sorts to empower polymorphic conduct that backings question arranged programming. An accommodating point of view: esteem sorts are more about memory and design control, reference sorts are more about base classes and virtual capacities to bolster polymorphism. As a matter of course, esteem sorts are copyable—they each have a duplicate constructor and a duplicate task administrator. When you indicate a reference sort, make the class non-copyable—incapacitate the duplicate constructor and duplicate task administrator—and utilize a virtual destructor, which bolsters the polymorphism. Esteem sorts are likewise about the substance, which, when they are duplicated, give both of you free esteems that you can adjust independently. Be that as it may, reference sorts are about personality—what sort of question it is—and consequently are now and then alluded to as polymorphic sorts. 
C++ is encountering a renaissance since power is above all else once more. Dialects like Java and C# are great when software engineer efficiency is vital, yet they demonstrate their constraints when power and execution are principal. For high effectiveness and power, particularly on gadgets that have restricted equipment, nothing beats present day C++
Not just the dialect is present day, the advancement apparatuses are, as well. Visual Studio makes all parts of the improvement cycle vigorous and productive. It incorporates Application Lifecycle Management (ALM) apparatuses, IDE upgrades like IntelliSense, device well disposed components like XAML, and building, troubleshooting, and numerous different instruments. 
The articles in this piece of the documentation give abnormal state rules and best practices for the most essential elements and methods for composing current C++ programs.
For more information, see the StackOverflow article what C++ idioms are deprecated in C++11
Previous Post
Next Post

post written by:

0 coment�rios: