Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #7946
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: static_cast, cast operator, and constructors. |
| Date | 2011-07-19 11:29 +1200 |
| Message-ID | <98ju0cFl78U3@mid.individual.net> (permalink) |
| References | <4e24b4fd$0$11125$cc2e38e6@news.uslec.net> |
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.
> Behavior I am seeing is that the templated version is called and then
> bases are called on the result of the cast operator.
>
> Is there a way to explicitly call the cast operator or is that what I'm
> supposedly doing?
Specialise the template constructor for ObjectB.
template <>
ObjectA::ObjectA<ObjectB>(ObjectB const&)
{
std::cout << "special" << std::endl;
}
--
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