gcc strange error

G

Gernot Frisch

This code:
class A
{
#define MK_OPERATOR_CL(zz) \
DGStr& operator zz=(const DGStr& a); \
DGStr& operator zz=(int a); \
DGStr& operator zz=(float a); \
DGStr& operator zz=(double a);

MK_OPERATOR_CL(+)
};


gives:
parse error before `)'
declaration of `operator +' as non-function

with gcc. MSVC compiles w/o problem. Any idea?


--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);}

________________________________________
Looking for a good game? Do it yourself!
GLBasic - you can do
www.GLBasic.com
 
W

Wouter Lievens

Gernot Frisch said:
This code:
class A
{
#define MK_OPERATOR_CL(zz) \
DGStr& operator zz=(const DGStr& a); \
DGStr& operator zz=(int a); \
DGStr& operator zz=(float a); \
DGStr& operator zz=(double a);

MK_OPERATOR_CL(+)
};


gives:
parse error before `)'
declaration of `operator +' as non-function

with gcc. MSVC compiles w/o problem. Any idea?


Try g++'s -E option.
 
J

John Harrison

Gernot Frisch said:
This code:
class A
{
#define MK_OPERATOR_CL(zz) \
DGStr& operator zz=(const DGStr& a); \
DGStr& operator zz=(int a); \
DGStr& operator zz=(float a); \
DGStr& operator zz=(double a);

MK_OPERATOR_CL(+)
};


gives:
parse error before `)'
declaration of `operator +' as non-function

with gcc. MSVC compiles w/o problem. Any idea?

You can't do that, gcc is right. I don't have the standard handy but either
zz= is not meant to be substituted or it is but a space is added between the
+ and the =, I suspect the later and VC++ is just compiling

operator + =

as a 'helpful extension'.

What you need is the token pasting operator ##

#define MK_OPERATOR_CL(zz) \
DGStr& operator zz##=(const DGStr& a); \

That concatenates the replacement for zz and the = into a single token.

john
 

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,754
Messages
2,569,526
Members
44,997
Latest member
mileyka

Latest Threads

Top