By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,194 Members | 819 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,194 IT Pros & Developers. It's quick & easy.

gcc strange error

P: n/a
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
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Gernot Frisch" <Me@Privacy.net> schreef in bericht
news:2n***********@uni-berlin.de...
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.
Jul 22 '05 #2

P: n/a

"Gernot Frisch" <Me@Privacy.net> wrote in message
news:2n***********@uni-berlin.de...
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
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.