I have the follow code:

In this code i want initialized an object of cube!
but when i did this,
I initialized an array of matrix_type
and in each object of the array matrix_type i initialized an object of array_type!

BUT, if i try this with a matrix and with a array classes, it`s all ok!

but when i did this with cube class, the follow things happen:

1) when initialized the array object of each object in array matrix. the respective object of type array, dont initialized with the number in paremeter 'y_index', but less than!

can somebody helpe-me???

obs.: i am from brazil, sorry about english

the code:

class Array_IloNumVar : public Array<IloNumVar>{
    private:
        const IloEnv &env;
        float inf, sup;
        const bool type;

    public:

        Array_IloNumVar(int y_enter, const IloEnv &env_enter, float inf_enter, float sup_enter, bool type_enter)
        :
        env(env_enter),
        inf(inf_enter),
        sup(sup_enter),
        Array<IloNumVar>(),
        type(type_enter)
        {
            cout << "Construtor Array_IloNumVar   y = " << y_enter << endl;
            Array<IloNumVar>::y = y_enter;
            Initialized_Array(array, y_enter);

            for(int i = 0 ; i < y_enter; i++)
                Initialize(array[i]);
            cout << "Saiu Array_IloNumVar " << endl;
        }

        virtual ~Array_IloNumVar(){

        };

        virtual void Initialized_Array(IloNumVar ** &original_array, int y_index){
            cout << "Initialized_Array    y = " << y_index << endl;  
            original_array = new IloNumVar*[y_index];

            cout << "Saiu do Initialized_Array    y = " << y_index << endl;

        }
        void Initialize(IloNumVar * &element){
            if(element != NULL){
                if(type == FLOAT_TYPE)
                    *element = IloNumVar(env, inf, sup, ILOFLOAT);
                else if(type == INT_TYPE)
                    *element = IloNumVar(env, (int)inf, (int)sup, ILOINT);
            }
            else 
                cout << "Initializa Array_IloNumVar : elemento nao esta inicializado\n" << endl;
        }


};

class Matrix_IloNumVar : public Matrix<IloNumVar>{
    private:
        Array_IloNumVar ** matrix;

        void Initialized_Matrix(Array_IloNumVar ** &original_matrix, int original_x){
            cout << "Initialized_Matrix   x = " << original_x << endl;   
            original_matrix = new Array_IloNumVar*[original_x];

        }

    public:

        Matrix_IloNumVar(int x_enter, int y_enter, const IloEnv &env_enter, float inf_enter, float sup_enter, bool type_enter)
        :
        Matrix<IloNumVar>()
        {
            cout << "\nConstrutor Matrix_IloNumVar    x = " << x_enter << "   y = " << y_enter<< endl;    
            Matrix<IloNumVar>::x = x_enter; 
            Matrix<IloNumVar>::y = y_enter;  

            Initialized_Matrix(matrix ,x);

            cout << "2    Construtor Matrix" << endl;

            for(int i = 0 ; i < x ; i++)             
                matrix[i] = new Array_IloNumVar(y_enter, env_enter, inf_enter, sup_enter, type_enter);


            cout << "Saiu Construtor Matrix" << endl; 
        }

        virtual ~Matrix_IloNumVar(){};

};


class Cube_IloNumVar : public Cube<IloNumVar>{
    private:
        Matrix_IloNumVar ** cube;

        void Initialized_Cube(Matrix_IloNumVar ** &original_cube, int z ){
            cout << "Initialized_Cube " << endl;

            original_cube = new Matrix_IloNumVar*[z];
            if(original_cube == NULL)
                cout << "Erro ao Inicializar o Cube_IloNumVar cube" << endl;

            cout << "SAIU Initialized_Cube " << endl;

        }

    public:

        Cube_IloNumVar(int z_enter, int x_enter, int y_enter, const IloEnv &env_enter, float inf_enter, float sup_enter, bool type_enter)
        :
        Cube<IloNumVar>()
        {
            cout << "Construtor IloNumVarCube     z = " << z_enter <<"    x = "<< x_enter<< " y = "<<y_enter << endl;
            Cube<IloNumVar>::z = z_enter;
            Cube<IloNumVar>::x = x_enter;
            Cube<IloNumVar>::y = y_enter;

            if(Cube<IloNumVar>::Empty()){
                cout << "Parametros Ilegais para a Construcao do Cubo \n";
                return;
            }

            Initialized_Cube(cube, z_enter);

            cout << "2    Construtor IloNumVarCube" << endl;

            for(int i = 0 ; i < z_enter ; i++)               
                cube[i] = new Matrix_IloNumVar( x_enter, y_enter, env_enter, inf_enter, sup_enter, type_enter);

            cout << "Saiu Construtor IloNumVarCube" << endl;

        }

        virtual ~Cube_IloNumVar(){};



};

best explication:

when i do

Cube_IloNumVar cube = new Cube_IloNumVar(3, 4, 5)

the array`s what initialized, dont initialized whit 5 elements but less then this! and i know that cause in the function


virtual void Initialized_Array(IloNumVar ** &original_array, int y_index){
cout << "Initialized_Array y = " << y_index << endl;
original_array = new IloNumVar*[y_index];

cout << "Saiu do Initialized_Array y = " << y_index << endl;

}


i can see the parameter what i passed to initialized

but when start the instanciate of each object in the array, on the function:
void Initialize(IloNumVar * &element){
if(element != NULL){
if(type == FLOAT_TYPE)
*element = IloNumVar(env, inf, sup, ILOFLOAT);
else if(type == INT_TYPE)
*element = IloNumVar(env, (int)inf, (int)sup, ILOINT);
}

i saw what i didnt have 5 elements, but less than!

this thing just happen when i try initialized a cube!

when i did this with matrix or array classes, DONT HAPPEN

if you want test, i cant pass all code to you! but they can move IloNumVar, ou creat an class with this name

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.