The following class is meant to store a single bool and an array of 100 integers. I want a constructor that takes as parameters a single bool and a 100-element array (which are then copied into the object). The obvious way to write this is the following
class Info {
private:
const int contents[100];
const bool symmetric;
public:
Info (const int contents[100], bool symmetric) : contents(contents), symmetric(symmetric) {}
// ...
};
But unfortunately this does not compile, the contents argument in the member initialiser list (the third contents
on that line) seems to be regarded as a pointer.
Can I get this to work or is this a C++ limitation?
- I do not want to use
std::array
orstd::vector
for space and efficiency reasons. [edited] Mine is a C++ syntax question and not about whetherstd::array
is efficient or not. The answer may be useful in related situations that do not allow the use ofstd::array
. [end edited] - Initializing in the constructor body does not work, because
contents
isconst
.
I am using C++14 with clang (CLion in linux) and come from the Java world.