Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #7949
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: static_cast, cast operator, and constructors. |
| Date | 2011-07-19 11:57 +1200 |
| Message-ID | <98jvlqF8muU2@mid.individual.net> (permalink) |
| References | <4e24b4fd$0$11125$cc2e38e6@news.uslec.net> <98ju0cFl78U3@mid.individual.net> <4e24c29d$0$11121$cc2e38e6@news.uslec.net> |
On 07/19/11 11:44 AM, Noah Roberts wrote:
> On 7/18/2011 4:29 PM, Ian Collins wrote:
>> On 07/19/11 10:46 AM, Noah Roberts wrote:
>>> Considder:
>>>
>>> struct ObjectA
>>> {
>>> ObjectA(ObjectA const&);
>>>
>>> template< typename T>
>>> ObjectA(T const&);
>>>
>>> void fun() const;
>>> };
>>>
>>> struct ObjectB
>>> {
>>> operator ObjectA () const;
>>> };
>>>
>>> static_cast<ObjectA>(an_object_b).fun();
>>>
>>> Which constructor does the standard specify will be called during the
>>> static_cast: copy or template?
>>
>> Is the code complete? The only option is the template.
>
> No, there's a second option: apply the cast operator and call the copy
> operator with the result.
Your terminology is a little confused. There is a conversion (not cast)
operator and a copy constructor (not operator).
The sequence you describe required two levels of conversion, the
template constructor one.
Assignment or omitting the template constructor should call the
conversion operator:
ObjectA a = an_object_b;
--
Ian Collins
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
static_cast, cast operator, and constructors. Noah Roberts <dont@email.me> - 2011-07-18 15:46 -0700
Re: static_cast, cast operator, and constructors. Ian Collins <ian-news@hotmail.com> - 2011-07-19 11:29 +1200
Re: static_cast, cast operator, and constructors. Noah Roberts <dont@email.me> - 2011-07-18 16:44 -0700
Re: static_cast, cast operator, and constructors. Ian Collins <ian-news@hotmail.com> - 2011-07-19 11:57 +1200
Re: static_cast, cast operator, and constructors. Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-07-19 13:12 +0000
Re: static_cast, cast operator, and constructors. Noah Roberts <dont@email.me> - 2011-07-19 09:26 -0700
Re: static_cast, cast operator, and constructors. Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-07-20 18:52 +0000
Re: static_cast, cast operator, and constructors. James Kanze <james.kanze@gmail.com> - 2011-07-20 12:53 -0700
csiph-web