chenbos...@gmail.com wrote:
> I am learning STL and write my own simple codes to test the examples.
> When I compile (g++ -c -o A.o A.C) I got "A.h:13: error: parse error
> before `<' token". This must be a simple problem, just that I cannot
> see it. Please, anyone help me to figure it out? Thanks.
>
#include <functional>
> // A.h
> class A {
> public:
> A();
> int getA();
> private:
> int a;
> };
>
> int compare(A*, A*);
>
> struct Compare : public binary_function<A*, A*, bool> {
I think you mean:
struct Compare : public std::binary_function<A*, A*, bool> {
> bool operator()(A *aoo, A *boo) const {
> return compare(aoo, boo);
> }
> };
>
> // A.C
> #include "A.h"
>
> A::A() : a(0) {}
> int A::getA() { return a; }
>
> int compare(A *aoo, A *boo) {
> if (aoo->getA() < boo->getA()) return -1;
> if (aoo->getA() > boo->getA()) return 1;
> return 0;
> }
Best regards,
Tom
|