O'Reilly logo

Imperfect C++ Practical Solutions for Real-Life Programming by Matthew Wilson

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

Chapter 33. Multidimensional Arrays

As we saw in section 14.7, C and C++ do not support multidimensional arrays of dynamic size, except where all but the most significant dimension is of constant size. In other words, you can do the following:

void f(int x)
{
  new byte_t[x];
}

but not:

void f(int x, int y, int z)
{
  new byte_t[x][y][z]; // Error
}

Creating a multidimensional array can only be in this form:

const size_t Y = 10;
const size_t Z = Y * 2;

void f(int x)
{
  new byte_t[x][Y][Z];
}

This can be quite a restriction. For example, a couple of years ago I was working on a multimedia product user interface where the layout of the interface was dynamically retrieved from a central server over the Internet. The layout could be any possible combination ...

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