在构造函数中没有已知的从 'const int [5][4]' 到 'const int **' 的转换
no known conversion from 'const int [5][4]' to 'const int **' in a constructor
我有一个 class 这个构造函数:
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
我做错了什么?
谢谢大家的关注
如果可以的话,我会先为转换 table 创建一个 class,然后将构造函数更改为使用它而不是 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)
我假设过渡 table 是二次的。
我有一个 class 这个构造函数:
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
我做错了什么? 谢谢大家的关注
如果可以的话,我会先为转换 table 创建一个 class,然后将构造函数更改为使用它而不是 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)
我假设过渡 table 是二次的。