 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Me Guest
|
Posted: Thu Dec 18, 2003 9:06 am Post subject: reference to array conversion operator? |
|
|
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
|
Posted: Thu Dec 18, 2003 11:52 am Post subject: Re: reference to array conversion operator? |
|
|
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
|
Posted: Thu Dec 18, 2003 11:53 pm Post subject: Re: reference to array conversion operator? |
|
|
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
|
Posted: Fri Dec 19, 2003 7:39 am Post subject: Re: reference to array conversion operator? |
|
|
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 |
|
 |
|
|
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
|
|