Articles & Books

Quick Q: How does virtual inheritance solve the “diamond” (multiple inheritance) ambiguity?

Quick A: by making sure only one instance of each parent class is created.

Recently on SO:

How does virtual inheritance solve the “diamond” (multiple inheritance) ambiguity?

You want: (Achievable with virtual inheritance)

  A 
/ \ 
B   C 
\ / 
  D

And not: (What happens without virtual inheritance)

A   A 
|   |
B   C 
\ / 
  D

Virtual inheritance means that there will be only 1 instance of the base A class not 2.

Your type D would have 2 vtable pointers (you can see them in the first diagram), one for B and one for C who virtually inherit A. D's object size is increased because it stores 2 pointers now; however there is only one A now.

So B::A and C::A are the same and so there can be no ambiguous calls from D. If you don't use virtual inheritance you have the second diagram above. And any call to a member of A then becomes ambiguous and you need to specify which path you want to take.

New new() - The C++17's Alignment Parameter for the operator new() -- Bartlomiej Filipek

C++17's new and handy new operator that supports overaligned objects!

New new() - The C++17's Alignment Parameter for Operator new()

by Bartlomiej Filipek

From the article:

The whole deal about the new functionality is that you can forgot about the limitation of over-aligned data. It lets you write regular modern C++ code without worrying about specialized allocators or raw memory handling functions like std::aligned_alloc() or _aligned_malloc().

Back to Basics at CppCon 2019

It started!

Back to Basics at CppCon 2019

by Arthur O’Dwyer

From the article:

Tomorrow I’ll be flying out to Denver, Colorado, for CppCon 2019. This will be my busiest CppCon yet! Besides giving my “STL From Scratch” weekend course for the third year in a row, this year I’m also the chair of CppCon’s new “Back to Basics” track...

C++ Core Guidelines: Profiles--Rainer Grimm

To continue in the next one.

C++ Core Guidelines: Profiles

by Rainer Grimm

From the article:

Informally, profiles are a subset of rules of the C++ core guidelines for specific concerns such as type safety, bounds safety, and lifetime safety. Thanks to the guideline support library, they can be checked...

Cppcon-Tool Time 2019--Jon Kalb

Will you attend?

Tool Time 2019

by Jon Kalb

From the article:

Similar to tech labs at some other events, we’re offering the opportunity for anyone, from an author/creator, to a vendor, to a super-user, to represent a tool (app, library, framework, or service) and run their own table answering questions or showing demos...

C++17 - The Complete Guide now complete and available -- Nicolai M. Josuttis

A new the latest book by Nicolai M. Josuttis is now complete and available.

C++17 - The Complete Guide

by Nicolai M. Josuttis

About the book:

The book is a full description of all language and library features that were introduced and modified with C++17.

It contains plenty of examples and many hints from using these new features in practice.

It is availble at your local book store or here.

 

 

Quick Q: Removing item from vector, while in C++11 range 'for' loop?

Quick A: it is not possible

Recently on SO:

Removing item from vector, while in C++11 range 'for' loop?

No, you can't. Range-based for is for when you need to access each element of a container once.

You should use the normal for loop or one of its cousins if you need to modify the container as you go along, access an element more than once, or otherwise iterate in a non-linear fashion through the container.

For example:

auto i = std::begin(inv);

while (i != std::end(inv)) {
    // Do some stuff
    if (blah)
        i = inv.erase(i);
    else
        ++i;
}