Topic: References
Author: Adrian@mcmen.demon.co.uk (Adrian McMenamin)
Date: Tue, 5 Jul 1994 20:44:41 +0000 Raw View
Sorry if this is a FAQ but why is it not standard C++ to
allow the initialisation of a referenceto type foo with
a function that returns type foo?
--
Adrian
Adrian@mcmen.demon.co.uk
Author: konfjo@eua.ericsson.se (Fredrik Jonsson)
Date: 8 Jul 1994 06:14:12 GMT Raw View
In article 773441081snz@mcmen.demon.co.uk, Adrian@mcmen.demon.co.uk (Adrian McMenamin) writes:
>Sorry if this is a FAQ but why is it not standard C++ to
>allow the initialisation of a referenceto type foo with
>a function that returns type foo?
>--
>Adrian
>Adrian@mcmen.demon.co.uk
Do you mean something like this?
class Object { };
Object setup() {
return *new Object;
}
int main() {
Object& obj = setup();
}
I haven't verified if there are any violations against the standard in this
particular example but atleast there are no problems when compiling it.
_______________
Fredrik Jonsson
Author: jason@cygnus.com (Jason Merrill)
Date: Fri, 8 Jul 1994 10:06:23 GMT Raw View
>>>>> Adrian McMenamin <Adrian@mcmen.demon.co.uk> writes:
> Sorry if this is a FAQ but why is it not standard C++ to allow the
> initialisation of a referenceto type foo with a function that returns
> type foo?
Because doing so would involve binding a reference to a temporary object,
which is only allowed if the reference is to const foo.
Jason