In C ++, if an array is defined as a member of a class, initialization will occur.
As follows:
Class
{
Public:
A ();
~ A (){};
Int ABC [3];
}
The intuitive idea is:
A: ()
: ABC ({1, 2, 3 })
{
}
Sorry, you will see a syntax error during compilation.
Of course, the work und can be used here
A: ()
{
For (INT nloop = 1; nloop <= 3; nloop ++)
ABC [nloop] = nloop;
}
But what if we need to initialize an array of objects without the default structure? For example, Class B {public: B (int );~ B () {}; int m_nb;} B: B (int A): m_nb (){}
Class
{
Public:
A ();
~ A (){};
B ABC [3];
}
How should we initialize it? Here we can only use a work und.
Class
{
Public:
A ();
~ A (){};
B * ABC [3];
}
A: A () {ABC [0] = new B (1); ABC [1] = new B (2 ); ABC [2] = new B (3);} Of course, I may be too ignorant. If anyone knows the initialization syntax of the member array, please kindly advise.