我有替换失败的问题,一些类似问题的答案对我没有帮助。
这是主要部分:
template<int dim, int loop>
class Reference{
public:
//...
template<int r, int c> using matrix_t = int[r][c];
Reference(const matrix_t<dim, loop> &mat){}
};
template<int dim, int loop>
class Partition{
// ...
public:
// ...
template<int r, int c> using matrix = int[r][c];
template<int r, int c> void readPattern(const matrix<r,c> &pattern)
{
// ...
}
// ...
};
我将此模板称为:
// ...
const int DENOISE_UR[3][4] = {/*...*/};
Partition<1,2> partition;
partition.readPattern(DENOISE_UR);
// ...
使用clang ++(linux)进行编译时,会导致以下编译错误:
error: no matching function for call to 'readPattern'
note: candidate template ignored: substitution failure[ with r = 3, c = 4 ]
template<int r, int c> void readPattern(const matrix<r,c> &pattern)
为什么?
奇怪的是,上面的代码在Visual Studio 2013上编译和工作。
// ============================================= ===================
我很抱歉在编辑问题时我犯了错误。我发现单独使用这部分时它确实可以编译。但在我的项目中,它只提供上述编译错误信息。
所以我的项目一定存在一些问题。
// ============================================= ===================
经过一番努力,我通过添加类Reference<int dim, int loop>
有人可以帮我解决这个问题吗?