[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Problem with functor in g++
From: |
okronglis |
Subject: |
Problem with functor in g++ |
Date: |
23 Oct 2006 05:03:17 -0700 |
User-agent: |
G2/1.0 |
Hi,
I am having trouble compiling some templated code that uses functors in
g++. It compiles fine in VC8. Any idea what I could do to make this
work with g++?
code:
#include <iostream>
using namespace std;
template <class T>
class add
{
public:
T& operator()(T& t1, const T& t_inc)
{
t1 += t_inc;
return t1;
}
};
template <class T, class addition = add<T> >
class A
{
private:
T m_start;
T m_end;
public:
A(){}
~A(){}
void initialize(const T& start, const T& end)
{
m_start = start;
m_end = end;
}
template <class output_functor>
void do_loop(output_functor& o)
{
T var = m_start;
for ( int n = 0; var <= m_end; ++n )
{
o(var);
addition()(var,static_cast<T>(1));
}
}
};
struct output
{
void operator()(const int n)
{
cout << n << ", ";
}
};
int main(int argc, char* argv[])
{
A<int> a_int;
a_int.initialize(1,10);
a_int.do_loop(output());
getchar();
return 0;
}
Output from g++:
tst.cpp: In function 'int main(int, char**)':
tst.cpp:58: error: no matching function for call to 'A(int,add<int>
>::do_loop(output)'
tst.cpp:35: note: candidates are: void A<T,
addition>::do_loop(output_functor&) [with output_functor = output, T =
int, addition = add<int>]
Thanks,
Stefan
- Problem with functor in g++,
okronglis <=