By Adna Colakovic


2019-05-15 16:53:50 8 Comments

I wanted to make a matrix in dynamic memory using shared pointer that would then be pointing to array of pointers to integer. When all of the code is in main it works like a clock but when I try to break it up into functions, does nothing, doesn't even enter the for loops, gets into a function, gets out, that is all.

I tried to only have the allocation part in a function but to have value input in main, tried all kinds of parameters, I don't even know what I did and didn't try anymore to be frank

no errors no warnings, exited with code zero.

void alocation(shared_ptr<int*[]> &niz, int r, int k) {

    cout << "\nUnesite broj redova : ";
    cin >> r;
    cout << "\nUnesite broj kolona : ";
    cin >> k;
    niz.reset(new int*[r]);
    for (int i = 0; i < r; i++)
    {
        niz[i] = new int[k];
    }


}
void dealociraj(shared_ptr<int*[]> &niz, int r) {

    for (int i = 0; i < r; i++)
    {
        delete[] niz[i];
    }
    niz = nullptr;

}
void upis(shared_ptr<int*[]> niz, int r, int k) {

    for (int i = 0; i < r; i++)
    {

        for (int j = 0; j < k; j++)
        {

            cout << "\nniz[" << i << "][" << j << "] : ";
            cin >>niz[i][j];
        }
    }

}
void ispisivanje(shared_ptr<int*[]> niz, int r, int k) {

    for (int i = 0; i < r; i++)
    {
        for (int j = 0; j < k; j++)
        {
            cout << "\n niz[" << i << "][" << j << "] : " << niz[i][j];
        }
    }

}

0 comments

Related Questions

Sponsored Content

20 Answered Questions

[SOLVED] Can a local variable's memory be accessed outside its scope?

8 Answered Questions

[SOLVED] Should we pass a shared_ptr by reference or by value?

7 Answered Questions

[SOLVED] Difference in make_shared and normal shared_ptr in C++

  • 2014-01-03 02:44:38
  • Anup Buchke
  • 80284 View
  • 228 Score
  • 7 Answer
  • Tags:   c++ c++11 shared-ptr

1 Answered Questions

[SOLVED] Memory error on displaying opencv matrix

2 Answered Questions

[SOLVED] shared_ptr to an array : should it be used?

4 Answered Questions

[SOLVED] Differences between unique_ptr and shared_ptr

1 Answered Questions

[SOLVED] Program with dynamic matrix crashes upon reaching printf

  • 2015-02-19 15:05:16
  • Salvador Villarreal
  • 65 View
  • 1 Score
  • 1 Answer
  • Tags:   c arrays pointers

1 Answered Questions

[SOLVED] Matrix Printing using Pointers

Sponsored Content