Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

gcc compile error "parse error before"

0 views
Skip to first unread message

kusan...@gmail.com

unread,
Aug 15, 2006, 6:25:59 AM8/15/06
to
To all,

I've got a class like this:

class ParentObject
{
private:
char* mParentName;

public:
ParentObject (char* pParentName);
};

and using gcc to compile give me an error like this
ParentObject.h:2: error: parse error before "ParentObject"
ParentObject.h:3: error: syntax error before '{' token

I was wondering what might have gone wrong....

>From Jason (kusanagihk)

Thomas Maeder

unread,
Aug 15, 2006, 11:48:40 AM8/15/06
to
kusan...@gmail.com writes:

> To all,
>
> I've got a class like this:
>
> class ParentObject
> {
> private:
> char* mParentName;
>
> public:
> ParentObject (char* pParentName);
> };
>
> and using gcc to compile give me an error like this
> ParentObject.h:2: error: parse error before "ParentObject"
> ParentObject.h:3: error: syntax error before '{' token

I can't reproduce this here.

Please post the minimal sufficient code snippet that causes the
compiler to behave the way you describe.


> I was wondering what might have gone wrong....

Probably the problem is at the end of the header #included just above
the one that defines class ParentObject, but unless we see enough
code, that's pure speculation.

Laurent D.A.M. MENTEN

unread,
Aug 15, 2006, 2:57:34 PM8/15/06
to

I have had this kind of problem with ms-dos CR/LF source files on a
linux box...

Hope is helps!

kusan...@gmail.com

unread,
Aug 16, 2006, 7:06:13 AM8/16/06
to
To all,

Oh thanks for your replies. I've got a good news and a bad news.

Good news: the problem's solved, since I'm writing a c++ program
instead of c (I mean I need to compile as c++) therefore I should use
g++ instead of gcc. After shifting to g++, everything's solved

Bad news: I continue to develop my school work on cygwin and got a
problem in creating an iterator, code are as follows:

[Buffer.h]
#include <stdio.h>
#include <list>

using namespace std;

template <class T>
class Buffer
{
private:
list<T> mBuffer;
list<T>::iterator aIter; // <-- this line of code got problem
public:
Buffer ()
{
printf ("[system] constructor end.");
}
~Buffer ()
{
printf ("[system] destructor end.");
}

// implementation depends on the concrete class
void* getElement (int pIndex);
};

[Buffer_Int.cpp]
#include "Buffer.h"

template <class T>
void* Buffer<T>::getElement (int pIndex)
{
return 0;

}

int main (int pNumArg, char** pArgs)
{
return 0;
}


the error is as follows:
$ g++ Buffer_Int.cpp -o out.exe
In file included from Buffer_Int.cpp:1:
Buffer.h:11: error: expected `;' before "aIter"

I used "list<T>::iterator aIter" and got an error; but it was
"list<int>::iterator aIter" everything's fine..... is that there are
some special syntax for template classes (not again.......?)


>From Jason (Kusanagihk)

Thomas Maeder

unread,
Aug 16, 2006, 9:59:28 AM8/16/06
to
kusan...@gmail.com writes:

> #include <stdio.h>
> #include <list>
>
> using namespace std;

This is hardly a good idea in a header, because it assumes that every
user of Buffer wants all the entities of namespace std pulled into the
global namespace.


> template <class T>
> class Buffer
> {
> private:
> list<T> mBuffer;
> list<T>::iterator aIter; // <-- this line of code got problem

Indeed.

When parsing this line, the compiler has to figure out what the name
iterator names. This isn't as obvious as it might seem, because the
program might later provide a specialization of list for some type,
and not declare iterator (or declare to name something different than
the base template does) and then instantiate Buffer on that type.

All the compiler can do is a little guessing, and the Standard
requires it to guess that iterator does *not* name a type, unless the
program explicitly says so:

typename list<T>::iterator aIter;

0 new messages