Re: pointers to functions
Carlos Moreno wrote:
somelawsbelongtoyou@gmail.com wrote:
[...]
Now, there's another problem -- quite subtle, mind you!
There is already something called "minus" in the standard
library -- you're only including <iostream>, which means that
in principle you would not expect the minus (part of the
<functional> facility, if I'm not mistaken) to be included;
but then, every part of the Standard Library has all its right
to include any other parts of the library that it decides to
use to implement its functionality.
And in fact, if this wasn't the case, his code couldn't compile,
because <iostream> doesn't define the << operators. (In almost
all, if not all, implementations, it includes <ostream>,
however, which does define them.)
Apparently, your compiler's <iostream> is deciding to make
use of the STL function objects, and it is importing minus
in the namespace std, causing ambiguity.
I'm not so sure about that. His error message didn't say
anything about any ambiguity, or refer to a problem with a
template in anyway. I don't think that there are many ways you
can use std::minus without following it with a <. As an
argument to a template parameter to a template is about the only
one which comes to mind. In this context, I would expect some
error along the lines of "'<' expected" if <iostream> included
<functional>.
So, make it Minus instead of minus. (no, do not listen to
those who are going to jump at it telling you that you must
avoid at all costs the use of "using namespace std;" :-))
And yet... It's the only solution which works. You can't really
expect a beginner to be aware of every single function in the
standard library -- even I'm not sure I know them all, and I'm
not exactly a beginner.
--
James Kanze GABI Software
Conseils en informatique orient?e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S?mard, 78210 St.-Cyr-l'?cole, France, +33 (0)1 30 23 00 34
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]