O'Reilly logo

Game Programming using Qt 5 Beginner's Guide - Second Edition by Lorenz Haas, Witold Wysota, Pavel Strakhov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Pointer invalidation

First, implicit sharing means that holding any references or pointers to the container's content is disallowed when there is a possibility of changing this object or any object that shares the same buffer. The following small example illustrates the problem:

// don't do this!
QVector<int> x { 1, 2, 3 };
int *x0 = x.begin();
QVector<int> y = x;
x[0] = 42;
qDebug() << *x0; // output: 1

We initialized the x0 variable with the pointer to the first element of the x vector. However, when we set a new value for that element and then tried to read it using the pointer, we got the old value again.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required