包含模板的头文件中"not declared in scope"错误

"not declared in scope" error in a header file with templates

本文关键字:not declared scope 错误 in 文件 包含模      更新时间:2023-10-16

因此,我创建了一个包含以下内容的头文件:

namespace A
{
template<int a>
void foo(...)
{
    //This throws a "test was not declared in this scope" error:
    boost::function< bool (int, int)> t = test<a>; 
}
template<int a>
bool test(int c, int d)
{
    //Do stuff;
}
}

但是,编译时会抛出错误,我不知道为什么。 测试显然在范围内。

boost:ref(test<a>)&test<a>替换test<a>仍然不起作用。

有什么想法吗?

你至少需要声明一些东西,然后才能使用它。在此之前,编译器并不知道它实际上存在。

namespace A
{
template<int a>
bool test(int c, int d);
template<int a>
void foo(...)
{
    //This throws a "test was not declared in this scope" error:
    boost::function< bool (int, int)> t = test<a>; 
}
template<int a>
bool test(int c, int d)
{
    //Do stuff;
}
}