0

I have a class with this constructor:

Dfa(const int n_state, const int dim_alf, const string *alf, const int s_state, const int** tt_copy );

I try to create a dfa object like this:

const string alph[3] = {"a","b","c"};
const int ttable[5][4] = {1, 2, 4, 0, 3, 4, 1, 0, 4, 3, 2, 0, 4, 4, 4, 1, 4, 4, 4, 0};
Dfa reference_Tomita15 = new Dfa(5,3,alph,0,ttable);

This code gives me the error:

candidate constructor not viable: no
  known conversion from 'const int [5][4]' to 'const int **' for 5th argument

What am I doing wrong? Thank you all for the attention

R zu
  • 2,034
  • 12
  • 30
  • 2
    Multi-dimensional arrays don't decay to pointers as one-dimensional arrays do (https://stackoverflow.com/questions/12674094/array-to-pointer-decay-and-passing-multidimensional-arrays-to-functions). Can you change the constructor? – Jens May 10 '18 at 20:33
  • @Jens Strictly saying, they do decay to pointers in the exact same way as 1D arrays. But the resulting pointer type could be different from what you expect: `int [5][4]` becomes `int (*)[4]`. – HolyBlackCat May 10 '18 at 21:08
  • Thank you for your comments. No I cannot change the constructor –  May 11 '18 at 10:57

1 Answers1

0

If you can, I would first create a class for the transition table, and then change the constructor to use that instead of a C-array to

class transition_table {
};

Dfa(int n_state, int dim_alf, const string& alf, int s_state, transtition_table tt)

If you create it from a statically allocated array, you can do

template<size_t DIM> Dfa(int n_state, const string& alf, int s_state, int (&tt)[DIM][DIM])

or even better

template<size_t DIM> Dfa(int n_state, const string& alf, int s_state, std::array<std::array<int, DIM>, DIM> tt)

I assume that the transition table is quadratic.

Jens
  • 9,058
  • 2
  • 26
  • 43
  • Thank you so much, that's a really good point, I'll give it a try :) –  May 11 '18 at 11:00