![]() |
|
|
Welcome to the { mindfrost82.com } forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
Return type
Hi,
I am trying to figure out which portion of the N2691 explicitly mentions that the return type of a function can be a pointer or reference to an incomplete type. $8.3.5/9 of course states that "The type of a parameter or the return type for a function definition shall not be an incomplete class type....", but I could not figure out anything with respect to pointer or reference to incomplete type for return type. Please let me know. struct A; struct B{ A& f(); // function returning reference to an incomplete type }; struct A{}; A& B::f(){static A a; return a;} int main(){ B object; } Regards, Dabs. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |
|
|||
|
Re: Return type
On Aug 9, 8:59 am, rkld...@gmail.com wrote:
> I am trying to figure out which portion of the N2691 explicitly > mentions that the return type of a function can be a pointer or > reference to an incomplete type. $8.3.5/9 of course states that "The > type of a parameter or the return type for a function definition shall > not be an incomplete class type....", but I could not figure out > anything with respect to pointer or reference to incomplete type for > return type. class T; T foo(); T * bar(); T & baz(); foo returns an incomplete type. bar returns a pointer to an incomplete type, and baz returns a reference to an incomplete type. T is an incomplete type. A pointer to T is a pointer to an incomplete type. A pointer to an incomplete type is a complete type. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |
|
|||
|
Re: Return type
rkldabs@gmail.com wrote:
> Hi, > > I am trying to figure out which portion of the N2691 explicitly > mentions that the return type of a function can be a pointer or > reference to an incomplete type. $8.3.5/9 of course states that "The > type of a parameter or the return type for a function definition shall > not be an incomplete class type....", but I could not figure out > anything with respect to pointer or reference to incomplete type for > return type. > > Please let me know. > > struct A; > > struct B{ > A& f(); // function returning reference to an incomplete type > }; > > struct A{}; > > A& B::f(){static A a; return a;} > int main(){ > B object; > } > > Regards, > Dabs. > As far as I know, returning a reference or a pointer to an incomplete type has been legal since C++98. In fact, returning a pointer to an incomplete type has been legal in C since C90. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |
|
|||
|
Re: Return type
rkldabs@gmail.com ha scritto:
> Hi, > > I am trying to figure out which portion of the N2691 explicitly > mentions that the return type of a function can be a pointer or > reference to an incomplete type. $8.3.5/9 of course states that "The > type of a parameter or the return type for a function definition shall > not be an incomplete class type....", but I could not figure out > anything with respect to pointer or reference to incomplete type for > return type. A pointer or reference type is always a complete type, regardless of the fact the pointed/referred type is incomplete. So you don't need an explicit statement to allow them nor there's a reason to disallow them. Their case is thus covered by the general statement you already mentioned. HTH, Ganesh -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |
![]() |
|
| Thread Tools | Search this Thread |
| Display Modes | |
|
|