0

I have the following function in pseudocode

int [][] multiply(int[][] A, int[][] B)

What would be the c++ equivalent for this I have the following

int [][] multiply(int A[][], int B[][])

But it doesn't work, gives compiler errors.

Shaheem Khan
  • 103
  • 6
  • 6
    Don't use c-style arrays in c++ code. Use `std::array` or `std::vector` instead. Also refrain from posting _pseudo-code_. Post a [MCVE] with the verbatim error messages text. –  Jan 29 '18 at 01:59
  • Unbounded arrays are a ty..., a category of incomplete types. Therefore, the unbounded dimension can only be the outer one. Also, this is all straight C. Use good C++ abstractions. – Alexander Huszagh Jan 29 '18 at 02:03
  • Look here: https://stackoverflow.com/questions/8767166/passing-a-2d-array-to-a-c-function – Bartosz Woźniak Jan 29 '18 at 02:03
  • You must specify the first dimension. int A[SIZE][], int B[SIZE][] – Omid CompSCI Jan 29 '18 at 02:19
  • Are they fixed size arrays or do they change at runtime? – Galik Jan 29 '18 at 03:03

1 Answers1

1

vector<vector<int>> multiply(const vector<vector<int>> &A, const vector<vector<int>> &B)

Sid S
  • 5,887
  • 2
  • 12
  • 23
  • 4
    Nested `std::vector` structures have some drawbacks. Their cache hit behavior isn't really optimal. In most cases it's better to wrap just a simple `std::vector` containing a contiguous memory space into a little helper class, and calculate the row and column offsets internally. Also just posting a piece of code without any further explanation as an answer is unlikely to be useful. –  Jan 29 '18 at 02:35
  • @TheDude does not abide. – Justin Randall Jan 29 '18 at 02:42
  • @Justin What do you mean exactly? Anything wrong with what I said? –  Jan 29 '18 at 02:44
  • [Cultural joke.](https://en.wikipedia.org/wiki/The_Big_Lebowski) He means you don't like the answer. – user4581301 Jan 29 '18 at 02:49
  • No. I know a gentleman who's called himself The Dude far longer than the movie's been around. I had to explain the Abides thing to him a few years ago. Interesting side-note, Popping The Big Lebowski into google to get the wiki link also popped up a show time. Apparently the film is being screened a a local cinema this coming weekend. I think I'll go. – user4581301 Jan 29 '18 at 16:44