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

C

chenboston

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;
}
 
T

Thomas Tutone

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 said:
// 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 said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top