C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

reference to array conversion operator?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Me
Guest





PostPosted: Thu Dec 18, 2003 9:06 am    Post subject: reference to array conversion operator? Reply with quote



I've been pulling my hair out trying to figure out the syntax for this
for the past 10 minutes but I can't get it to work:

typedef const char (&r2a)[10];

struct foo {
operator r2a() const;
};

If I use "r2a" it works, but what is the syntax for it without the
typedef (i.e. the long way)? I don't need a lecture why I shouldn't do
this, I just want to know the correct syntax for educational purposes.

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Francis Glassborow
Guest





PostPosted: Thu Dec 18, 2003 11:52 am    Post subject: Re: reference to array conversion operator? Reply with quote



In article <682764f7.0312172214.3937b0f1 (AT) posting (DOT) google.com>, Me
<anti_spam_email2003 (AT) yahoo (DOT) com> writes
Quote:
I've been pulling my hair out trying to figure out the syntax for this
for the past 10 minutes but I can't get it to work:

typedef const char (&r2a)[10];

struct foo {
operator r2a() const;
};

If I use "r2a" it works, but what is the syntax for it without the
typedef (i.e. the long way)? I don't need a lecture why I shouldn't do
this, I just want to know the correct syntax for educational purposes.

I am not certain but I suspect that this maybe one of the cases where a
typdef of some form is essential. The problem is that the parser will
assume that '(' starts the parameter list unless it is the case of
operator() in which case the next symbol must (I think) be another '('.

That there are cases where a typedef is required to support the C++
syntax is itself educational:-)

--
Francis Glassborow ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
or http://www.robinton.demon.co.uk


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Ben Hutchings
Guest





PostPosted: Thu Dec 18, 2003 11:53 pm    Post subject: Re: reference to array conversion operator? Reply with quote



Me wrote:
Quote:
I've been pulling my hair out trying to figure out the syntax for this
for the past 10 minutes but I can't get it to work:

typedef const char (&r2a)[10];

struct foo {
operator r2a() const;
};

If I use "r2a" it works, but what is the syntax for it without the
typedef (i.e. the long way)? I don't need a lecture why I shouldn't do
this, I just want to know the correct syntax for educational purposes.

There is no way to name such a conversion operator without using a
type alias. The syntax for the type name following the "operator"
keyword is restricted in order to avoid ambiguities (I think).

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
John Potter
Guest





PostPosted: Fri Dec 19, 2003 7:39 am    Post subject: Re: reference to array conversion operator? Reply with quote

On 18 Dec 2003 04:06:03 -0500, [email]anti_spam_email2003 (AT) yahoo (DOT) com[/email] (Me) wrote:

Quote:
I've been pulling my hair out trying to figure out the syntax for this
for the past 10 minutes but I can't get it to work:

Put your fingers on google, not your hair. :)

Quote:
typedef const char (&r2a)[10];

struct foo {
operator r2a() const;
};

If I use "r2a" it works, but what is the syntax for it without the
typedef (i.e. the long way)? I don't need a lecture why I shouldn't do
this, I just want to know the correct syntax for educational purposes.

A recent thread in this newsgroup concluded that it is something which
can not be done without a typedef.

Rest educated.

John

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.