extending the life of temporary objects in C++ -


I'm reading this:

  // Example 3 Derivative Factory () ; // A derivative object vs. zero () {Census base & amp; B = Factory (); // Call Derivative: generated here // ... use b ...} // calls received: ~ Generally generated here - Base no: Base + virtual sending!  

And I understand the first and second examples, but I do not consider the third example. False, what is loyalty / references and what is the 'viral dispatch' example would be good.

If you write the code written below:

  zero ) {Base * b = new derivative; // Call Derivative: generated here // ... use b ... delete b; }  

Because B is base * , even if the base destroyer was virtual, because virtual dispatch will be called derivative because the The object type indicated by the base indicator is derived.

Instead of

  void g () {derived * d = new derived; // Call Derivative :: Here generated // ... Use D ... Delete D; }  

Regardless of whether a Base Distribute is virtual or not, a derivative district is called. No virtual transmissions are necessary.

The author wants to emphasize the example 3, even , if the base killer is not virtual, then the derivative will be asked. Because the destroyer is not being called because the reference is going out of the scope, but because there is no need of temporary item (type derivative) from the base context. (Must be the Coast)


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -