【发布时间】:2018-03-13 19:36:19
【问题描述】:
#include <iostream>
template<typename T>
void f(T x)
{
g(x); // g is a dependent name
};
void g(int a)
{
std::cout << a;
}
int main()
{
int a = 12;
f(a);
}
//this should be point of declaration for f<int>
上面的代码给出了编译错误“‘g’没有在这个范围内声明,并且在实例化点通过参数相关的查找没有找到任何声明”。
由于 g 是一个从属名称,它的名称在实例化时应该是可见的。请告诉我我错过了什么?
【问题讨论】:
-
您在声明或定义之前尝试使用
g。 -
在模板前添加
g声明。