M
Maitre Bart
First, I describe my setup in 3 points. Then I describe what I want to do,
and describe the error I get.
1) I have a container GTTable container pointer to data (class GT *).
2) I made a template class based on mem_fun1, which in my version accepts 2
arguments in each call: one that is variable on each call (VA, typically
coming from the above container) and one that is fixed on each call (FA,
kind of constant provided by the user):
template<class R, class T, class VA, class FA>
class mem_fun1_arg_t : binary_function<T*, VA, R>
{
public:
explicit mem_fun1_arg_t(R (T::*p)(VA va, FA fa), FA fa) : pmf(p),
arg(fa) {}
R operator()(T* p, VA va) const {return (p->*pmf)(va, arg);}
private:
R (T::*pmf)(VA va, FA fa);
FA arg;
};
3) I paired the above template class with the following template function:
template<class R, class T, class VA, class FA>
inline static mem_fun1_arg_t<R, T, VA, FA> mem_fun1_arg(R (T::*p)(VA va, FA
fa), FA fa)
{
return mem_fun1_arg_t<R, T, VA, FA>(p, fa);
}
What I want to do is to find an element in GTTable that matches another
object's predicate, while providing a constant as the second argument during
the calls. Each call within the STL algorithm should look like:
ptrObject->Pred2(ptrGT, k)
Given ptrObject is of type "class CSomeClass", I use:
find_if(GTTable->begin(),
GTTable->end(),
bind1st(mem_fun1_arg(&CSomeClass:red2, k), ptrObject));
However, the compiler keeps complaining the same 7 errors in a row:
c:\program files\microsoft visual studio\vc98\include\functional(158): error
C2248: 'first_argument_type': cannot access public typedef declared in class
'binary_function<CSomeClass *,GT const *,bool>'
c:\program files\microsoft visual studio\vc98\include\functional(24): see
declaration of 'first_argument_type'
GTManager.cpp(396): see reference to class template instantiation
'binder1st<mem_fun1_arg_t<bool,CSomeClass,GT const *,int>>' being compiled
I tried another test with the standard mem_fun1 (derived from
binary_function) in order to verify if it was compiling:
find_if(GTTable->begin(),
GTTable->end(),
bind1st(mem_fun1(&CSomeClass:red1), ptrObject));
and it works (the compiler does not display any error message).
I wonder what is wrong in my template pair?
Is it my compiler? (MSVS6)
Note: I have the equivalent templates, adapted for unary_function, and there
no error.
Thanks for any help.
and describe the error I get.
1) I have a container GTTable container pointer to data (class GT *).
2) I made a template class based on mem_fun1, which in my version accepts 2
arguments in each call: one that is variable on each call (VA, typically
coming from the above container) and one that is fixed on each call (FA,
kind of constant provided by the user):
template<class R, class T, class VA, class FA>
class mem_fun1_arg_t : binary_function<T*, VA, R>
{
public:
explicit mem_fun1_arg_t(R (T::*p)(VA va, FA fa), FA fa) : pmf(p),
arg(fa) {}
R operator()(T* p, VA va) const {return (p->*pmf)(va, arg);}
private:
R (T::*pmf)(VA va, FA fa);
FA arg;
};
3) I paired the above template class with the following template function:
template<class R, class T, class VA, class FA>
inline static mem_fun1_arg_t<R, T, VA, FA> mem_fun1_arg(R (T::*p)(VA va, FA
fa), FA fa)
{
return mem_fun1_arg_t<R, T, VA, FA>(p, fa);
}
What I want to do is to find an element in GTTable that matches another
object's predicate, while providing a constant as the second argument during
the calls. Each call within the STL algorithm should look like:
ptrObject->Pred2(ptrGT, k)
Given ptrObject is of type "class CSomeClass", I use:
find_if(GTTable->begin(),
GTTable->end(),
bind1st(mem_fun1_arg(&CSomeClass:red2, k), ptrObject));
However, the compiler keeps complaining the same 7 errors in a row:
c:\program files\microsoft visual studio\vc98\include\functional(158): error
C2248: 'first_argument_type': cannot access public typedef declared in class
'binary_function<CSomeClass *,GT const *,bool>'
c:\program files\microsoft visual studio\vc98\include\functional(24): see
declaration of 'first_argument_type'
GTManager.cpp(396): see reference to class template instantiation
'binder1st<mem_fun1_arg_t<bool,CSomeClass,GT const *,int>>' being compiled
I tried another test with the standard mem_fun1 (derived from
binary_function) in order to verify if it was compiling:
find_if(GTTable->begin(),
GTTable->end(),
bind1st(mem_fun1(&CSomeClass:red1), ptrObject));
and it works (the compiler does not display any error message).
I wonder what is wrong in my template pair?
Is it my compiler? (MSVS6)
Note: I have the equivalent templates, adapted for unary_function, and there
no error.
Thanks for any help.