Re: conversion sequence
Am 19.07.2011 23:22, schrieb Noah Roberts:
Considder:
struct bob
{
bob(ObjectA const&);
template < typename T >
bob(T const&);
void fun() const;
};
struct ref
{
operator bob() const;
};
static_cast<ObjectA>(a_ref_instance).fun();
Where does the standard specify what happens here? I can't find
anywhere that states what method of conversion is preferred when both
constructor and conversion operator could do the job.
Sorry, but your pseudo-code is so incomplete/contradictory that it seems
impossible for me to give a reasonable answer. I tried to complete your
code to a program ending in something like this:
struct ObjectA {};
struct bob
{
bob(ObjectA const&);
template < typename T >
bob(T const&);
void fun() const;
};
struct ref
{
operator bob() const;
} a_ref_instance;
int main() {
static_cast<ObjectA>(a_ref_instance).fun();
}
Looking at this, I do not understand how you could expect that a ref
object can be converted into an ObjectA object. Neither do I understand
where the fun() function from ObjectA enters the game.
What I want to happen is the conversion operator get called on
a_ref_instance and then the copy constructor to make a bob equivalent to
the one provided by a_ref_instance.
Is there a way to force that sequence? What I'm getting is a call to
the templated constructor in bob with ref as T.
Please provide a complete example if you want serious help.
Greetings from Bremen,
- Daniel Kr?gler
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]