Note that there are some explanatory texts on larger screens.

plurals
  1. POc++ working with 2d arrays
    primarykey
    data
    text
    <p>Currently I'm learning C++ and I've been trying to create a simple image processing library for learning purposes.</p> <p>One of my features is eroding an image. As input it has two 2d arrays, and it returns another 2d array. All these arrays are of variable size. Let's give you an example of what I want to achieve.</p> <pre><code>int image[5][5] = { {'0', '0', '0', '0','0'}, {'0', '1', '1', '1','0'}, {'0', '0', '1', '0','0'}, {'0', '1', '1', '1','0'}, {'0', '0', '1', '0','0'}, }; int kernel[3][3] = { {'0', '1', '0'}, {'1', '1', '1'}, {'0', '1', '0'}, }; </code></pre> <p>Then I want to pass them to my function (this doesn't compile, but it serves as an example of what I want).</p> <pre><code>int** erode(int image[][], int kernel[][]); </code></pre> <p>So far, I've read quite a bit about this. All I've read is that the columns can be of variable length, but the rows can't. So I should be change it to the following:</p> <pre><code>int** erode(int image[][5], int kernel[][3]); </code></pre> <p>But that's not really want I want either, because well, the image can be 10*10 and the kernel could be 5*5. So this isn't optimal in this situation either.</p> <p>Then what I've read is creating a class, that internally stores the image as a 1d array and makes it look like a 2d array. Also I've read about using the <code>Boost.MultiArray</code> class to do this. But well I'm not too happy about that either. Because then I'm forcing the people that use it to also use those classes. And I think it's creating a lot of complexity for something that seems really simple (at least it is in C#)</p> <p>To be honest, I can't imagine there isn't an easier way to do this. Optimally I'd say only use classes/methods from the standard <code>C++11</code> library. <strong>How would you solve this problem?</strong></p> <p>Timo</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload