Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > What's wrong with these simple codes? (parse error before `<' token)

Reply
Thread Tools

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

 
 
chenboston@gmail.com
Guest
Posts: n/a
 
      03-16-2006
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;
}

 
Reply With Quote
 
 
 
 
Thomas Tutone
Guest
Posts: n/a
 
      03-16-2006
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

 
Reply With Quote
 
 
 
 
chenboston@gmail.com
Guest
Posts: n/a
 
      03-16-2006
Thanks, Tom. It solves the problem!

Best,
-Chen

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple program with a simple(?) error -- what's wrong? RichardOnRails Ruby 3 07-21-2008 01:26 PM
Should I delete these memory before exit process Osamede Zhang C++ 9 10-10-2006 10:51 AM
Could corrupt/wrong version/missing instances of these filescause Win98se to not BOOT. David_nj_7@mailbolt.com Computer Support 9 11-17-2005 06:38 PM
What's Wrong with these code? Richard C++ 2 09-28-2004 10:54 AM
Any recent news on these old TV shows coming to DVD before the sun explodes? DVD Video 4 05-24-2004 09:53 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57