What's wrong with these simple codes? (parse error before `<' token)

Discussion in 'C++' started by chenboston@gmail.com, Mar 16, 2006.

  1. Guest

    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.

    // A.h
    class A {
    public:
    A();
    int getA();
    private:
    int a;
    };

    int compare(A*, A*);

    struct Compare : public 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;
    }
    , Mar 16, 2006
    #1
    1. Advertising

  2. 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
    Thomas Tutone, Mar 16, 2006
    #2
    1. Advertising

  3. Guest

    Thanks, Tom. It solves the problem!

    Best,
    -Chen
    , Mar 16, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. nitin
    Replies:
    2
    Views:
    1,119
    David Cattarin
    Jul 7, 2003
  2. learning_C++

    error: parse error before `(' token

    learning_C++, Sep 21, 2004, in forum: C++
    Replies:
    4
    Views:
    9,965
    Sharad Kala
    Sep 21, 2004
  3. Replies:
    2
    Views:
    2,814
    Malcolm
    Aug 20, 2005
  4. nick

    parse error before '=' token

    nick, Oct 13, 2005, in forum: C Programming
    Replies:
    22
    Views:
    1,213
    Dave Thompson
    Oct 24, 2005
  5. Junmin H.
    Replies:
    6
    Views:
    320
    Charlie Gordon
    Sep 18, 2007
Loading...

Share This Page