【发布时间】:2018-03-06 16:32:22
【问题描述】:
我有一个带有这个构造函数的类:
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
我做错了什么? 谢谢大家的关注
【问题讨论】:
-
多维数组不会像一维数组那样衰减为指针 (stackoverflow.com/questions/12674094/…)。你能改变构造函数吗?
-
@Jens 严格来说,它们确实以与一维数组完全相同的方式衰减到指针。但生成的指针类型可能与您期望的不同:
int [5][4]变为int (*)[4]。 -
感谢您的 cmets。不,我不能更改构造函数
标签: c++ constructor type-conversion implicit-conversion data-conversion