1

Topic: Question about const reference

Never like would meet before the such: const double &r = 0.1; Tell, please, the standard authorizes to create the reference to a constant?

2

Re: Question about const reference

Hello, Maxim Rogozhin, you wrote: > Never like would meet before the such: > > const double &r = 0.1; > > Tell, please, the standard authorizes to create the reference to a constant? From time immemorial, and transient object lifetime lasts till the end of link life: struct foo {}; foo boo () {return foo ();}... {foo const& r = boo ();//the transient object will live till the end of framing ...}

3

Re: Question about const reference

Hello, Maxim Rogozhin, you wrote: > Never like would meet before the such: > > const double &r = 0.1; > > Tell, please, the standard authorizes to create the reference to a constant? 0.1 is not a constant, and a type literal double. Whether you met the following construction earlier? const std::string& s = "Hello!"; or such? void foo (const std::string& arg);//... foo ("World!");

4

Re: Question about const reference

Hello, Anatoly Shirokov, you wrote: > from time immemorial, and transient object lifetime lasts till the end of link life: Yes, but it for local links. And if so: const double &r = 0.1;//the global link int main () {return 0;}

5

Re: Question about const reference

Hello, Constructor, you wrote: a C> a C> const std::string& s = "Hello!"; the C> Is the local link? Or in global area of visibility? And in what advantage of such construction in comparison with const std:: string s ("Hello!");

6

Re: Question about const reference

Hello, Maxim Rogozhin, you wrote: a C>> a C>> const std::string& s = "Hello!"; the C>> > Is the local link? Or in global area of visibility? Can be both local, and global. > And in what advantage of such construction in comparison with > > const std:: string s ("Hello!"); > Advantages are not present, but anybody and did not promise it.

7

Re: Question about const reference

Hello, Constructor, you wrote: the C> Can be both local, and global. The C> is not present Advantage, but anybody and did not promise it. In your example there is a type conversion from const char* in std:: string. And in this example const double &r = 0.1; there is a temporary variable double because the link can be initialized only a variable, so?

8

Re: Question about const reference

Hello, Maxim Rogozhin, you wrote: > In your example there is a type conversion from const char* in std:: string. However. Here one more example: const double &r = 0; > And in this example > > const double &r = 0.1; > > there is a temporary variable double because the link can be initialized only a variable, so? The constant link can be anchored to transient object.

9

Re: Question about const reference

Hello, Maxim Rogozhin, you wrote: > Hello, Anatoly Shirokov, you wrote: >> from time immemorial, and transient object lifetime lasts till the end of link life: > Yes, but it for local links. And if so: > > const double &r = 0.1;//global link > int main () {> return 0; >} > the Global link prolongs transient object lifetime for program runtime.