【发布时间】:2010-07-30 09:38:40
【问题描述】:
g++ 4.4 拒绝编译对将函数本地类作为模板参数的模板函数的调用。像这样:
// Given this:
template <typename C>
int f(const C& c) {
return c.g();
}
// This compiles fine:
struct C1 {
int g() const { return 42; }
};
int h1() {
return f(C1());
}
// But this doesn't:
int h2() {
struct C2 {
int g() const { return 42; }
};
return f(C2()); // error: no matching function for call to "f(h2()::C2)"
}
// Nor does this:
int h3() {
struct C3 {
int g() const { return 42; }
};
return f<C3>(C3()); // same error
}
什么给了?我该如何进行这项工作? (在修剪 this 的实际程序中,“h”是一个成员函数,“C”必须是一个嵌套类,以便它隐含地成为“h”是其成员的类的朋友。)
【问题讨论】: