Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Variable is not declared in the scope error in c++?

I’m new bee in c++! I’m to iterate over integers using the for loop, but getting the error

               error: ‘frame’ was not declared in this scope
               auto position_array = (*frame)[i][j];

But as you can see in the code below it is declared

    auto ds = data_file.open_dataset(argv[1]);
    // auto frame = data_file.read_frame(ds, 0); // inside the loop
    for (int i = 0; i < 3; ++i)
        auto frame  = data_file.read_frame(ds, i);

    for (size_t i = 0; i < nsamples; ++i) {
        for (size_t j = 0; j <= 2; ++j) { // j<=2 assign all columns 
            auto position_array = (*frame)[i][j];
        }
        corr.sample(frame);
    }
    corr.finalise();

It works fine if I use the commented second line. But now I want to iterate over the second variable of data_file.read_frame(ds, i) and the error comes up! What am I doing wrong? Do I need to declare int frame = 0; before the for loop? For the brevity I just post the code with the error, incase some one need to see the whole code you’re welcome!!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Sounds like you need a nested for loop. Using

for (int i = 0; i < 3; ++i)
{
    auto frame  = data_file.read_frame(ds, i);

    for (size_t j = 0; j < nsamples; ++j) {
        for (size_t k = 0; k <= 2; ++k) { // j<=2 assign all columns 
            auto position_array = (*frame)[i][j];
        }
        corr.sample(frame);
    }
}

Lets you get each frame, and then process each element of each frame.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading