This question pertains to both array initialization and SystemC module hierarchies.
I have a class that is non-copyable, non-movable, and no default constructor:
class Object : public sc_module {
public:
Object(string name, Configuration config);
Object(const CPU& that) = delete;
};
and another class that has an array of these:
class Object2 : public sc_module {
public:
std::array<Object, 2> obj_array;
Object2() : obj_array <--??-->
{}
};
I need to initialize obj_array
with Objects
, which can't be copied and can't be moved.
I've tried a whole bunch of combinations and the one thing that compiles is:
class Object2: {
public:
std::array<Object, 2> obj_array;
//note the double braces on this initializer list
Object2() : obj_array {{ {"string1", config}, {"string2", config} }}
{}
};
It works, but I see some weird behavior later on in the code: when I print out the names of the Objects
in obj_array
, the first one is correct Object2.string1
but the next one is really weird Object2.string1.string2
when it should just be Object2.string2
).
I know a lot of people have asked pretty similar questions, but I'm trying to figure out exactly what's going on here. It also seems to me like I've got one too many braces in that initializer list, but it won't compile otherwise.
Am using g++ 6.4.0 with flag -std=c++14
The thing is if I create another array in the body of the constructor, eg class Object2: { public: std::array obj_array; //note the double braces on this initializer list Object2() : obj_array {{ {"string1", config}, {"string2", config} }} { Obj arr[2] {{"test", config}, {"test2", config}}; } };
Everything appears OK. arr
Object names are correct, as are their parents.
I know this is an esoteric question, but I need help understanding exactly what mechanisms are going on during my obj_array initialization.