Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   function overloading: direct-match vs trivial-conversion (http://www.velocityreviews.com/forums/t610005-function-overloading-direct-match-vs-trivial-conversion.html)

subramanian100in@yahoo.com, India 04-13-2008 05:26 AM

function overloading: direct-match vs trivial-conversion
 
Suppose T is a type.

Consider the two functions:

void fn(T& first)
{
....
}

void fn(T const & second)
{
....
}

Suppose I have the declaration
T obj;

If I call fn(obj), then the function, void fn(T& first) will be
called. This is because:
When both
1) 'T' to 'T&' (this is a direct match)
2) 'T' to 'T const &' (this involves trivial conversion)
are present, direct match takes higher precedence. If direct match is
not found, only then trivial conversion is considered. That is, if the
first function void fn(T& first) is not present, only then the second
function void fn(T const & second) will be called.

Is my above understanding correct ?

Kindly clarify.

Thanks
V.Subramanian

Looney 04-13-2008 07:13 AM

Re: function overloading: direct-match vs trivial-conversion
 
On Apr 13, 3:26 pm, "subramanian10...@yahoo.com, India"
<subramanian10...@yahoo.com> wrote:
> Suppose T is a type.
>
> Consider the two functions:
>
> void fn(T& first)
> {
> ...
>
> }
>
> void fn(T const & second)
> {
> ...
>
> }
>
> Suppose I have the declaration
> T obj;
>
> If I call fn(obj), then the function, void fn(T& first) will be
> called. This is because:
> When both
> 1) 'T' to 'T&' (this is a direct match)
> 2) 'T' to 'T const &' (this involves trivial conversion)
> are present, direct match takes higher precedence. If direct match is
> not found, only then trivial conversion is considered. That is, if the
> first function void fn(T& first) is not present, only then the second
> function void fn(T const & second) will be called.
>
> Is my above understanding correct ?
>
> Kindly clarify.
>
> Thanks
> V.Subramanian


yes that is correct .
check out http://accu.org/index.php/journals/268
for a details


All times are GMT. The time now is 08:03 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.