0

そこで、次のヘッダー ファイルを作成します。

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;
}
}

ただし、コンパイル時にエラーがスローされますが、その理由はわかりません。テストは明らかに範囲内です。

orに置き換えtest<a>ても機能しません。boost:ref(test<a>)&test<a>

何か案は?

4

1 に答える 1

3

使用する前に、少なくとも何かを宣言する必要があります。コンパイラは、それより前に実際に存在することを知りません。

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;
}
}
于 2012-07-01T23:26:44.483 に答える