This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Initialize C ++ object array in constructor?

I am facing issues with initialization of an object array within the Constructor. I would like to initialize my array using initialization from brace-enclosed lists. But the armcc compiler for some reason, doesn't compile my code nor throw me a warning!

For example, the array would be of "Component" type:

Fullscreen
1
2
3
4
5
6
7
8
class Component
{
public:
Component(const uint8_t componentValue);
private:
const uint8_t ComponentValue;
};
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Next, the "Device" class, would utilize the "Component" in an array.

Fullscreen
1
2
3
4
5
6
7
8
class Device
{
public:
Device();
private:
Component components[3];
};
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Now, within the Device.cpp, I try to initialize the array in the default constructor call as:

Fullscreen
1
2
3
Device::Device()
: components{Component(3),Component(4),Component(5)}
{}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

I have set my compilation flags to -cpp11. Also, this code compiles on a "arm-none-eabi-g++" compiler.

Why am I not able to compile this on armcc 5.06?

0