Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > function overloading: direct-match vs trivial-conversion

Reply
Thread Tools

function overloading: direct-match vs trivial-conversion

 
 
subramanian100in@yahoo.com, India
Guest
Posts: n/a
 
      04-13-2008
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
 
Reply With Quote
 
 
 
 
Looney
Guest
Posts: n/a
 
      04-13-2008
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Function versus pointer to function, in context of std::function,huh? Alf P. Steinbach C++ 10 07-27-2011 05:51 AM
Function pointer to void function and int function Giannis Papadopoulos C Programming 5 09-05-2005 09:06 PM
How override ALL function calls? (Is there a "function call function"?) seberino@spawar.navy.mil Python 2 08-01-2005 12:38 PM
write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter komal C++ 6 01-25-2005 11:13 AM
Passing a C++ object's member function to a C function expecing a function pointer! James Vanns C++ 7 01-21-2004 02:39 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57