|
Hi DavidCrow,
It is also my coding style not to use &array.
It is code written by other people.
regards,
George
|
|
|
|
|
Hello everyone,
In the following statements,
<br />
template <class R, class T> class mem_fun_t : public unary_function <T*, R><br />
<br />
{<br />
<br />
R (T::*pmf)()<br />
...<br />
}<br />
1. I think pmf is a type of function pointer, the return type of the function is R and the function is a member function of type (class) T. Is my understanding correct?
2. If yes, what is the parameter list of the function? Empty parameter list?
3. I doubt whether it is useful to define a function pointer with empty parameter list -- too restricted.
thanks in advance,
George
|
|
|
|
|
Read documentation http://msdn2.microsoft.com/en-us/library/c8hzs937(VS.80).aspx[^] and you'll be able to answer all the questions yourself.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Hi CPallini,
I do not think your reply has anything to do with my question. I am asking function pointer, not how to use unary_function itself.
regards,
George
|
|
|
|
|
Yeah, you're right. I missed the point. I struck my reply's content. Now, turning back to your question:
George_George wrote: 3. I doubt whether it is useful to define a function pointer with empty parameter list -- too restricted.
A lot of class methods usually take 0 arguments and their usefulness is, usually again, out of doubt.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Thanks CPallini,
I want to confirm that, the declaration of variable pmf could be pointed to any member functions of class (type) T which returns type R and no input parameters? Right?
R (T::*pmf)()
regards,
George
|
|
|
|
|
Technically pmf is a member variable of class mem_fun_t whoose type is pointer to a method of class T, accepting zero arguments and returning an instance of class R .
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
nevermind. i said a mistake
|
|
|
|
|
I think a day I'll become mad because of a George_George question.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
lol. keep it up, don't let me alone
|
|
|
|
|
I am sorry to make you mad, CPallini. Maybe my question is too hard?
regards,
George
|
|
|
|
|
|
Thanks CPallini,
It is just for fun, technical fun.
regards,
George
|
|
|
|
|
Cool, thanks CPallini!
regards,
George
|
|
|
|
|
1. the code shown here calls a member function in the class T which has no parameters and which returns a variable or type R.
2. as said formerly, the function accepts no parameters.
3. it is certainly useful to have such a function, even though it gets no parameters. the point is that is calls such a function in the class T; that means, every class used MUST have such a function existing, but also it means that every class used so defines its own behavior.
|
|
|
|
|
Thanks toxcct,
1. I do not quite catch your points, why a class must implement a function without any parameters?
<blockquote class="FQ"><div class="FQA">toxcct wrote:</div>that means, every class used MUST have such a function existing, but also it means that every class used so defines its own behavior. </blockquote>
2. I want to confirm that, the declaration of variable pmf could be pointed to any member functions of class (type) T which returns type R and no input parameters? Right?
R (T::*pmf)()
regards,
George
|
|
|
|
|
George_George wrote: 1. I do not quite catch your points, why a class must implement a function without any parameters?
because it does something which doesn't need any further inputs from the caller.
here, the function is used as a functor, that means it is called internally from the STL algorithm you're using, to do a certain action on your class, but the algorithm wouldn't know what to pass it if it had to anyway.
George_George wrote: 2. I want to confirm that, the declaration of variable pmf could be pointed to any member functions of class (type) T which returns type R and no input parameters?
exactly. so, I think the compiler would probably complain (to be verified though) if it canoot determine which function to call if it find more than one.
|
|
|
|
|
Hi toxcct,
Your below description is not true. See my sample and it could compile ok.
toxcct wrote: exactly. so, I think the compiler would probably complain (to be verified though) if it canoot determine which function to call if it find more than one.
class Foo
{
public:
int Foo1() {};
int Foo2() {};
};
class Goo
{
public:
int (Foo::*pmf)();
};
int main()
{
return 0;
}
regards,
George
|
|
|
|
|
I SAID "I think" and "probably" which denotes a not sure at all. so give me my 5 back, dork
|
|
|
|
|
|
|
Done!
regards,
George
|
|
|
|
|
Why you delete your reply?
|
|
|
|
|
because i asked him to. it was a double post.
|
|
|
|
|
Ok but a question did you get notify when someone answer to your reply? I dont know it depends to these changes or no?
|
|
|
|