mthiffau
mthiffau

Reputation: 133

Header declaration for multi-dimensional array of unknown size in auto-generated cpp file?

As part of a project I'm working on, I've got a tool written in python that reads a CSV data file and generates a c++ file containing a statically declared 3 dimensional array. What the dimensions of the array are depend on the data in the CSV file and can change from compile to compile.

The declaration/definition looks like this:

const double aero_coeffs[81][25][8] = { ...

I've written a header to accompany the generated cpp file, and I'd really prefer not to have to generate that as well. However I get an error if I try to do this:

extern const double*** aero_coeffs;

or this (which I think is actually just the equivalent):

extern const double aero_coeffs[][][];

Any thoughts on the best way to go about this?

Upvotes: 0

Views: 993

Answers (1)

Nikola Benes
Nikola Benes

Reputation: 2711

You could perhaps use std::vector instead. With the new c++11 initalizer lists syntax, your generated file can be very similar. Something like:

std::vector< std::vector< std::vector< double > > > coeffs = {
    { {1, 2, 3}, {4, 5, 6} },
    { {7, 8, 9}, {0, 0, 0} } };

Then, in the header, you just use:

extern std::vector< std::vector< std::vector< double > > > coeffs;

Upvotes: 4

Related Questions