Working on Windows with VS2005 and struggling to understand the error messages I’m getting. If this question has been asked before, I’m sorry. I couldn’t find it.
Class I’m testing:
#include <functional>
using std::unary_function;
template<typename F, typename G>
struct UnaryConvolution : unary_function<typename G::argument_type,typename F::result_type>{
UnaryConvolution(const F &_f, const G &_g) : m_F(_f), m_G(_g){}
result_type operator()(const argument_type &_arg){
return m_F( m_G( _arg ) );
}
F m_F;
G m_G;
};
unit test I’ve written:
using std::bind2nd;
using std::equal_to;
using std::less;
bool unaryConvolution_test(){
UnaryConvolution obj(bind2nd( equal_to<bool>(), true ), bind2nd( less<int>(), 5 ));
return obj( 3 );
}
and errors I’m getting:
- error C2955: ‘UnaryConvolution’ : use of class template requires template argument list
- error C3848: expression having type ‘UnaryConvolution’ would lose some const-volatile qualifiers in order to call ‘_Result UnaryConvolution::operator ()(const _Arg &)’
- error C2514: ‘UnaryConvolution’ : class has no constructors
even adding the line int val = 3 and then passing val has no effect. (BTW, project is forbidden to use Boost or any 3rd party library. Don’t ask, I try not to.)
UnaryConvolutionis a class template, not a class. You need to specify the template arguments with which to instantiate the template. For example,(I’ve used
function, which you can get from Boost, C++ TR1, or C++0x, in place of the actual return type ofbind2nd, which isn’t quite as straightforward. If you don’t have access to some implementation offunction, then you’ll need to go figure out the return type ofbind2nd)