#include <boost/bind.hpp>
template <typename U>
class A
{
U unused;
public:
void foo()
{
boost::bind(&A<U>::check<int>, this, _1)(2);
}
template <typename T>
bool check (T value)
{
if(!value) printf("empty\n");
}
};
int main (void)
{
A<int> a;
a.foo();
}
при сборке gcc 4.1.2 ошибка на выделенной строке
zzz.c: In member function ‘void A<U>::foo()’:
zzz.c:10: ошибка: expected primary-expression before ‘int’
zzz.c:10: ошибка: expected `)' before ‘int’
в чем проблема?
Здравствуйте, Аноним, Вы писали:
А>А>#include <boost/bind.hpp>
А>template <typename U>
А>class A
А>{
А> U unused;
А>public:
А> void foo()
А> {
А> boost::bind(&A<U>::check<int>, this, _1)(2);
А> }
А> template <typename T>
А> bool check (T value)
А> {
А> if(!value) printf("empty\n");
А> }
А>};
А>int main (void)
А>{
А> A<int> a;
А> a.foo();
А>}
А>
А>при сборке gcc 4.1.2 ошибка на выделенной строке
А>zzz.c: In member function ‘void A<U>::foo()’:
А>zzz.c:10: ошибка: expected primary-expression before ‘int’
А>zzz.c:10: ошибка: expected `)' before ‘int’
А>в чем проблема?
void foo()
{
boost::bind(&A<U>::template check<int>, this, _1)(2);
}
?
KP>KP>void foo()
KP> {
KP> boost::bind(&A<U>::template check<int>, this, _1)(2);
KP> }
KP>
KP>?
спасибо, помогло! все время забываю о таком использовании keyword template
кстати можно чуть упростить:
boost::bind(&A::template check<int>, this, _1)(2);