Topic: Defining type within return type of function
Author: Hyman Rosen <hyrosen@mail.com>
Date: Fri, 23 Aug 2002 05:23:16 CST Raw View
Peter Koch Larsen wrote:
> Jie Zhang <zhangjie@magima.com.cn> wrote
>>Does C++ standard say that defining types within return type
>>are forbidden? I cannot find it. Can anyone give me a hint?
8.3.5/6
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: "Roger Orr" <rogero@howzatt.demon.co.uk>
Date: 23 Aug 2002 10:25:11 GMT Raw View
Peter Koch Larsen wrote in message
<61c84197.0208220113.b6399d8@posting.google.com>...
>Jie Zhang <zhangjie@magima.com.cn> wrote in message
news:<ajv0e8$6ui$1@debian.bentium.com>...
>> I have a question on defining type within return type of function.
>> According to the C++ standard, function-definition can be
>>
>> decl-specifier-seq_{opt} declarator ctor_initializer_{opt} function-body
>>
>> and decl-specifier-seq can be
>>
>> class-specifier
>>
>> That is to say, we can define a class within return type of function.
>>
No, unfortunately this is explicitly disallowed by the standard:-
buried in 8.3.5 Functions 8 Declarators
"Types shall not be defined in return or parameter types."
Roger Orr
--
MVP in C++ at www.brainbench.com
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: pkl@mailme.dk (Peter Koch Larsen)
Date: Thu, 22 Aug 2002 16:43:01 GMT Raw View
Jie Zhang <zhangjie@magima.com.cn> wrote in message news:<ajv0e8$6ui$1@debian.bentium.com>...
> I have a question on defining type within return type of function.
> According to the C++ standard, function-definition can be
>
> decl-specifier-seq_{opt} declarator ctor_initializer_{opt} function-body
>
> and decl-specifier-seq can be
>
> class-specifier
>
> That is to say, we can define a class within return type of function.
>
> But for the following code, gcc report errors:
> sss.cpp:2: ISO C++ forbids defining types within return type
> sss.cpp:2: semicolon missing after declaration of `class A'
> sss.cpp: In function `int fun()':
> sss.cpp:4: cannot convert `A' to `int' in return
>
> This is the code:
> class A{} fun()
> {
> A a;
> return a;
> }
>
> Does C++ standard say that defining types within return type
> are forbidden? I cannot find it. Can anyone give me a hint?
> Thanks.
>
> Jie Zhang
This looks like a question for comp.std.c++ ;^)
Kind regards
Peter Koch Larsen
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]