Topic: MEMBER OPERATOR CHAR*()
Author: jason@cygnus.com (Jason Merrill)
Date: Thu, 10 Nov 1994 10:06:08 GMT Raw View
>>>>> David Sachs <b91926@fsgm01.fnal.gov> writes:
> but you cannot declare operator char**(); // only 1 * allowed
Huh? How'd you come up with that? From the latest WP:
conversion-function-id:
operator conversion-type-id
conversion-type-id:
type-specifier-seq conversion-declaratoropt
conversion-declarator:
ptr-operator conversion-declaratoropt
This seems to allow any number of '*'s.
Jason
Author: Alan@doughnut.demon.co.uk (Alan Bellingham)
Date: Thu, 10 Nov 1994 13:17:28 +0000 Raw View
In article: <9411051638.0NDS900@chrysalis.org> howard.harkness@chrysalis.org writes:
> class foo
> {
> public:
> foo(); // constructor, no return type per ARM
> int somefn(); // fn returning int
> operator char*(); // no return type?
> ...
> private:
> char* rep;
> ...
> }
> ...
> foo::operator char*() {return rep;} // no return type
Return type: 'char *'
Consider:
1) operator const HorriblyLongNameClass const * ()
2) const HorriblyLongNameClass const * operator const HorriblyLongNameClass const * ()
3) const HorriblyLongNameClass * operator const HorriblyLongNameClass const * ()
3 is self contradicting, ergo *wrong*
2 is long winded
1 tells the compiler all it needs to know
Alan Bellingham
--
Alan@doughnut.demon.co.uk "... not many creatures are twenty feet across,
Alan@episys.win-uk.net one inch thick and deep fried." Terry Pratchett
Author: b91926@fsgm01.fnal.gov (David Sachs)
Date: 10 Nov 1994 11:11:49 -0600 Raw View
jason@cygnus.com (Jason Merrill) writes:
>>>>>> David Sachs <b91926@fsgm01.fnal.gov> writes:
>> but you cannot declare operator char**(); // only 1 * allowed
>Huh? How'd you come up with that? From the latest WP:
> conversion-function-id:
> operator conversion-type-id
> conversion-type-id:
> type-specifier-seq conversion-declaratoropt
> conversion-declarator:
> ptr-operator conversion-declaratoropt
>This seems to allow any number of '*'s.
>Jason
The ARM only allowed 1 "*". The standard may have changed since then.
Author: howard.harkness@chrysalis.org
Date: Sat, 05 Nov 94 16:38:40 Raw View
I ran into a description of member operator char*() in
Coplien's book _Advanced C++_, and I was a bit confused. I
followed his examples and was able to successfully implement an
operator char*() for one of my own projects, but I haven't found
any mention of the unusual syntax in the ARM, namely:
class foo
{
public:
foo(); // constructor, no return type per ARM
int somefn(); // fn returning int
operator char*(); // no return type?
...
private:
char* rep;
...
}
...
foo::operator char*() {return rep;} // no return type
operator char*() has no return type specified in the definition,
and the Borland compiler does indeed reject any attempt to say
"char* operator char*()", even though the function does indeed
return a pointer to char.
Could someone please explain the rationale behind this syntax,
and perhaps point me to some addition reference material? The only
book I've found this in is Coplien's, but that may be because I
don't really know exactly what it is called.
I would prefer e-mail. Given sufficient interest, I will
summarize responses here.
Thanks in advance,
<< howard.harkness@chrysalis.org >>
---
MegaMail 2.10 #0:
Author: "Ronald F. Guilmette" <rfg@rahul.net>
Date: 8 Nov 1994 09:51:31 GMT Raw View
In article <9411051638.0NDS900@chrysalis.org>,
<howard.harkness@chrysalis.org> wrote:
>operator char*() has no return type specified in the definition,
>and the Borland compiler does indeed reject any attempt to say
>"char* operator char*()", even though the function does indeed
>return a pointer to char.
>
> Could someone please explain the rationale behind this syntax,
The rationale for neither requiring nor allowing an explicit return type
specification on any type conversion operator is simple and obvious. It
just isn't necessary to (redundantly) specify the type which the function
will yield.
--
-- Ron Guilmette, Sunnyvale, CA ---------- RG Consulting -------------------
---- E-mail: rfg@segfault.us.com ----------- Purveyors of Compiler Test ----
-------------------------------------------- Suites and Bullet-Proof Shoes -
Author: b91926@fsgm01.fnal.gov (David Sachs)
Date: 9 Nov 1994 10:39:43 -0600 Raw View
billyoc@dpscon.uucp.netcom.com (Billy O'Connor) writes:
...
>Are these two tokens doing double duty, i.e., defining the operator
>and the return type at the same time? I'm going through the Coplien
>book myself.
>> operator char *(); // no return type?
Yes they are doing double duty. I think you will find it
referenced under something like type conversion or conversion
operators (I am away from my copy of the ARM).
In any event the target type that you can specify for a conversion
operator member function is highly restricted.
e.g. you can legally declare a member function
operator char(); or operator const char(); or
operator char*();
but you cannot declare operator char**(); // only 1 * allowed
However you can use a typedef to make the conversion target type
as complicated as needed. e.g.
typedef char (*ccfunc)(char) // function pointer ...
class ...
operator ccfunc();
...
Author: billyoc@dpscon.uucp.netcom.com (Billy O'Connor)
Date: Tue, 08 Nov 94 22:42:10 GMT Raw View
howard.harkness@chrysalis.org writes in article <9411051638.0NDS900@chrysalis.org>:
>
>
> I ran into a description of member operator char*() in
> Coplien's book _Advanced C++_, and I was a bit confused. I
> followed his examples and was able to successfully implement an
> operator char*() for one of my own projects, but I haven't found
> any mention of the unusual syntax in the ARM, namely:
>
> class foo
> {
> public:
> foo(); // constructor, no return type per ARM
> int somefn(); // fn returning int
Are these two tokens doing double duty, i.e., defining the operator
and the return type at the same time? I'm going through the Coplien
book myself.
> operator char *(); // no return type?
^^^^ ^
Billy O'Connor email: billyoc@netcom.com
D.P.S. Consulting UUCP: dps@dpscon.uucp.netcom.com
Boston area OS/2 business solutions CIS: 74021,530