【发布时间】:2015-10-12 04:07:21
【问题描述】:
我有一个替换失败的问题,一些类似问题的答案对我没有帮助。
代码如下:
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)
{
// ...
}
// ...
};
我这样称呼这个模板函数:
int main()
{
// ...
const int DENOISE_UR[3][4] = {/*...*/};
Partition<1,2> partition;
partition.readPattern(DENOISE_UR);
// ...
}
使用 g++ 编译。
在使用clang++(linux)编译(clang++ -std=c++11 xxx.cpp)时,出现如下编译错误:
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)
为什么?
【问题讨论】:
-
oO 如果你删除了
Reference、it compiles...的定义... -
@Columbo 这正是问题所在。我需要在
Partition类中使用Reference类 -
@Columbo 将第一个别名模板更改为
long[r][c]:melpon.org/wandbox/permlink/0DHbcs3C0dm9H3gXò.Ó -
@JorenHeit 是的,但这不是错误。我已经修复了
namespace错误,但错误仍然存在。所以我已经提取了上面的问题。
标签: c++ templates c++11 g++ clang