I have:
1) NetBeans 7.3 2) Qt by Digia v4.8.4. 3) MinGW compiler.
Could you help me initialize my array? I have failed, unfortunately. I understand that I have to use initializer_list. But what to include into my files and how to organize everything is a mystery to me.
Will you be so kind as to help me?
Figure.h
#include <initializer_list>
class Figure: public QObject{
    Q_OBJECT
        private:        
                int shape[4][4][4];
Figure.cpp
Figure:: Figure(){
std::initializer_list<int> init;
auto init = std::initializer_list<int>
(    
            {                        
                            {0, 0, 0, 0}, 
                            {0, 1, 1, 0},
                            {0, 0, 1, 0},
                    {0, 0, 0, 0}
                    ,                        
                            {0, 0, 0, 0}, 
                            {0, 0, 1, 0},
                            {0, 1, 1, 0},
                    {0, 0, 0, 0}
                    ,                        
                            {0, 0, 0, 0}, 
                            {0, 1, 0, 0},
                            {0, 1, 1, 0},
                    {0, 0, 0, 0}
                    ,                        
                            {0, 0, 0, 0}, 
                            {0, 1, 1, 0},
                            {0, 1, 0, 0},
                    {0, 0, 0, 0}                        
            }
    );  
                ...
  private:        
    int shape[4][4][4] {                        
                           {{0, 0, 0, 0}, 
                            {0, 1, 1, 0},
                            {0, 0, 1, 0},
                            {0, 0, 0, 0}}
                    ,                        
                           {{0, 0, 0, 0}, 
                            {0, 0, 1, 0},
                            {0, 1, 1, 0},
                            {0, 0, 0, 0}}
                    ,                        
                           {{0, 0, 0, 0}, 
                            {0, 1, 0, 0},
                            {0, 1, 1, 0},
                            {0, 0, 0, 0}}
                    ,                        
                           {{0, 0, 0, 0}, 
                            {0, 1, 1, 0},
                            {0, 1, 0, 0},
                            {0, 0, 0, 0}}                        
    };
...
In your particular case, you don't even need to use initalizer_list explicitly because static array can be initialized in the place of definition, and this is done via the syntax in the example above (requires C++11 compliance).
Initialization of shape in constructor initialization list is possible too:
...
Figure::Figure(): shape {
                               {{0, 0, 0, 0}, 
                                {0, 1, 1, 0},
                                {0, 0, 1, 0},
                                {0, 0, 0, 0}}
                        ,                        
                               {{0, 0, 0, 0}, 
                                {0, 0, 1, 0},
                                {0, 1, 1, 0},
                                {0, 0, 0, 0}}
                        ,                        
                               {{0, 0, 0, 0}, 
                                {0, 1, 0, 0},
                                {0, 1, 1, 0},
                                {0, 0, 0, 0}}
                        ,                        
                               {{0, 0, 0, 0}, 
                                {0, 1, 1, 0},
                                {0, 1, 0, 0},
                                {0, 0, 0, 0}}
  } {
  ...
}
...
NOTE: Pay attention to the fact that you've missed additional parentheses in your try.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With