Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #12419
| From | "MikeWhy" <boat042-nospam@yahoo.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: c_str from anonymous std::string |
| Date | 2011-12-12 17:39 -0600 |
| Organization | A noiseless patient Spider |
| Message-ID | <jc63b5$3iu$1@dont-email.me> (permalink) |
| References | <381e2339-377a-4969-bf8a-7613b811632f@gl2g2000vbb.googlegroups.com> <b919c4e6-cd44-4695-ad09-3e0161de441f@y18g2000yqy.googlegroups.com> |
Goran wrote:
> On Dec 12, 8:57 am, Andrew Tomazos <and...@tomazos.com> wrote:
>> class X
>> {
>> operator std::string(); // stringify X instance
>>
>> };
>>
>> void f(const char*);
>>
>> X x = ...
>> f(string(x).c_str());
>>
>> According to the C++11 standard, will the destructor of std::string
>> be called before or after the call to f, or is it undefined?
>
> My understanding is that such temporaries is destroyed when statement
> is finished, which, here, is after the semicolon.
It should be further noted that "string(x)" here is an explicit C-style
typecast, syntactically identical to "((std::string)x)", followed by copy
construction of std::string, creating not just one, but *two* temporary
std::string. What a nasty bit of business. This isn't real code, is it? Just
some contrived nastiness to astonish and dismay job applicants?
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
c_str from anonymous std::string Andrew Tomazos <andrew@tomazos.com> - 2011-12-11 23:57 -0800
Re: c_str from anonymous std::string SG <s.gesemann@gmail.com> - 2011-12-12 00:10 -0800
Re: c_str from anonymous std::string Goran <goran.pusic@gmail.com> - 2011-12-12 00:21 -0800
Re: c_str from anonymous std::string "MikeWhy" <boat042-nospam@yahoo.com> - 2011-12-12 17:39 -0600
Re: c_str from anonymous std::string Tobias Müller <troplin@bluewin.ch> - 2011-12-13 07:13 +0000
Re: c_str from anonymous std::string Juha Nieminen <nospam@thanks.invalid> - 2011-12-13 07:38 +0000
Re: c_str from anonymous std::string Ian Collins <ian-news@hotmail.com> - 2011-12-13 20:49 +1300
Re: c_str from anonymous std::string Andrew Tomazos <andrew@tomazos.com> - 2011-12-13 02:19 -0800
Re: c_str from anonymous std::string "MikeWhy" <boat042-nospam@yahoo.com> - 2011-12-13 11:10 -0600
Re: c_str from anonymous std::string Andrew Tomazos <andrew@tomazos.com> - 2011-12-13 10:17 -0800
csiph-web