Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4123116
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:34:12+00:00 2026-05-20T23:34:12+00:00

float sampleGrid1[5][5][5] = { { {0.0, 0.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 0.0,

  • 0
float sampleGrid1[5][5][5] =
{
    {
        {0.0, 0.0, 0.0, 0.0, 0.0},
        {0.0, 0.0, 0.0, 0.0, 0.0},
        {0.0, 0.0, 0.0, 0.0, 0.0},
        {0.0, 0.0, 0.0, 0.0, 0.0},
        {0.0, 0.0, 0.0, 0.0, 0.0}

    },

    {
        {0.0, 0.0, 0.0, 0.0, 0.0},
        {0.0, 0.0, 0.0, 0.0, 0.0},
        {0.0, 0.0, 1.0, 0.0, 0.0},
        {0.0, 0.0, 0.0, 0.0, 0.0},
        {0.0, 0.0, 0.0, 0.0, 0.0}

    },

    {
        {0.0, 0.0, 0.0, 0.0, 0.0},
        {0.0, 0.0, 1.0, 0.0, 0.0},
        {0.0, 1.0, 1.0, 1.0, 0.0},
        {0.0, 0.0, 1.0, 0.0, 0.0},
        {0.0, 0.0, 0.0, 0.0, 0.0}

    },

    {
        {0.0, 0.0, 0.0, 0.0, 0.0},
        {0.0, 0.0, 0.0, 0.0, 0.0},
        {0.0, 0.0, 1.0, 0.0, 0.0},
        {0.0, 0.0, 0.0, 0.0, 0.0},
        {0.0, 0.0, 0.0, 0.0, 0.0}

    },

    {
        {0.0, 0.0, 0.0, 0.0, 0.0},
        {0.0, 0.0, 0.0, 0.0, 0.0},
        {0.0, 0.0, 0.0, 0.0, 0.0},
        {0.0, 0.0, 0.0, 0.0, 0.0},
        {0.0, 0.0, 0.0, 0.0, 0.0}

    }
};

typedef struct
{
  int Nx;
  int Ny;
  int Nz;
  float*** M;
}OG;

Relevant function:

OG *newOG(){
    OG *newOG = (OG *)malloc(sizeof(OG));
    if (newOG == NULL)
    {
        throw std::exception("newOG : no memory is available");
    }

    return newOG;
}

int initiateOG(OG *MyOG)
{

    ifstream dump("OGdump3.txt");

    if (dump.is_open())
    {   
        while ( dump.good() )
        {   
            dump >> MyOG->Nx;
            dump >> MyOG->Ny;
            dump >> MyOG->Nz;

            MyOG->M = new float**[MyOG->Nx];
            for(int i = 0; i < MyOG->Nx; i++)
            {
                MyOG->M[i] = new float*[MyOG->Ny];

                for(int j = 0; j < MyOG->Ny; j++)
                {
                    MyOG->M[i][j] = new float[MyOG->Nz];
                }
            }
            for(int z=0;z < MyOG->Nz; z++){

                for(int y=0;y < MyOG->Ny; y++){

                    for(int x=0;x < MyOG->Nx; x++){

                        dump >> MyOG->M[x][y][z];
                    }

                }

            }


        }

    dump.close();
    }
    else return 0; 
    return 1;
}

I want to hard code some sample grids into the code, but don’t know the best way to create them, do i have to use for loops?

i don’t want to change my typedef struct OG, if possible

Modified:

OG *occupancyGrid;

 void initialize3dArray(int x, int y, int z,float*** array)
    {
        array = new float**[x];
        for(int i = 0; i < x; i++)
        {
            array[i] = new float*[y];

            for(int j = 0; j < y; j++)
            {
                array[i][j] = new float[z];
            }
        }

    }

   void sampleOG1()
    {
        occupancyGrid = newOG();
        occupancyGrid->Nx = 5;
        occupancyGrid->Ny = 5;
        occupancyGrid->Nz = 5;

        initialize3dArray(5, 5, 5,occupancyGrid->M);

        for(int z=0;z < occupancyGrid->Nz; z++){

            for(int y=0;y < occupancyGrid->Ny; y++){

                for(int x=0;x < occupancyGrid->Nx; x++){

                    occupancyGrid->M[x][y][z] = sampleGrid1[x][y][z];
                }

            }

        }

    }

initialize3dArray this function doesn’t have compiling error, but still causing the program to crash

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T23:34:13+00:00Added an answer on May 20, 2026 at 11:34 pm

    Yes. that will not compile, because float[5][5][5] and float *** aren’t same type. They’re not even compatible type. One cannot convert to other automatically.

    However, float[5][5][5] can convert to float (*)[5][5] automatically. So this is legal code:

        float (*m)[5][5];
        m = sampleGrid1;  //legal - allowed!
    

    Demo : http://ideone.com/RwAwI

    So define OG as,

    struct OG
    {
      int Nx;
      int Ny;
      int Nz;
      float (*M)[5][5];
    };
    

    If you OG as defined above, then you can write this:

    OG* temp = newOG();
    temp->Nx = 5;
    temp->Ny = 5;
    temp->Nz = 5;
    occupancyGrid->M = sampleGrid1; //DONT use &
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

template struct A{ typedef float atype; typedef typename tB::btype typeB; }; template struct B{
struct Vector { float i,j,k; } std::vector pt[size]; ... = ... + pt[temp]; temp
float Calculate(const string &query) { std::cout << Query: << query << \n; unsigned int
I have this situation: { float foo[10]; for (int i = 0; i <
try it out: volatile float bob = -344.0f; unsigned int fred = (unsigned int)bob;
Integer and Float use 4 bytes of memory for storage. However the range of
float[float] aa = [2.2:7.7, 3.3:6.6, 1.1:4.4]; std.sort(aa); assert(aa == [1.1:4.4, 2.2:7.7, 3.3:6.6]); The above
float b = 1.0f; int i = (int)b; int& j = (int&)b; cout <<
float jk = 7700; float ck = 8000; - if i do int jk;
float minTime[7]={FLT_MAX}; for(int i=0;i<7;i++) cout << Min: << minTime[i] << endl; Why do I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.