Hi,
I’m having trouble with
the following design with vs 7.1 and wondering if anyone could offer a
workaround.
Particularly it seems that
the “.template operator” syntax isn’t liked. (This works on
gcc 4.0.3). Removing the ‘template’ keyword from the bind arguments
gives an error novel.
Any ideas would be warmly
welcomed!
s
#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <iostream>
class tmpl_operator
{
public:
template <typename T> void operator&( const T& rhs ) const
{
// do stuff
std::cout << rhs;
}
};
template <class T, class bound>
class command
{
public:
command(
T& obj, bound& instance ) : _instance(instance)
{
// works with gcc (4.0.3)
but not cl (7.1):
apply = boost::bind(&bound::template
operator&<T>,
instance,
obj);
// doesn’t
compile in vs:
//_instance.template
operator&<T>(obj);
// this compiles in vs though:
//
_instance.operator&<T>(obj);
}
void execute() { apply(); }
private:
bound
_instance;
boost::function<void
(void)> apply;
};
int main()
{
double dbl = 2.71;
tmpl_operator instance;
command<double,tmpl_operator>
test(dbl,instance);
test.execute();
}