我有一个带有这个构造函数的类:
Dfa(const int n_state, const int dim_alf, const string *alf, const int s_state, const int** tt_copy );
我尝试像这样创建一个dfa对象:
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);
此代码给出了错误:
candidate constructor not viable: no
known conversion from 'const int [5][4]' to 'const int **' for 5th argument
我做错了什么? 谢谢大家的关注
答案 0 :(得分:0)
如果可以的话,我首先要为转换表创建一个类,然后将构造函数更改为使用它而不是C数组
class transition_table {
};
Dfa(int n_state, int dim_alf, const string& alf, int s_state, transtition_table tt)
如果从静态分配的数组创建它,则可以执行
template<size_t DIM> Dfa(int n_state, const string& alf, int s_state, int (&tt)[DIM][DIM])
甚至更好
template<size_t DIM> Dfa(int n_state, const string& alf, int s_state, std::array<std::array<int, DIM>, DIM> tt)
我假设转换表是二次的。