Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > overload resolution

Reply
Thread Tools

overload resolution

 
 
Wolfgang Jeltsch
Guest
Posts: n/a
 
      08-30-2003
Hello,

consider the following code:
#include <iostream.h>

template < typename T >
int f( T v ) {
return 0;
}

int f( int i ) {
return i;
}

int main() {
cout << f( 1 ) << '\n';

return 0;
}

Is this correct and guaranteed to output 1? Or is there a conflict between
the template f which can be instantiated to
int f< int >( int )
and the function f which is declared as
int f( int )?

Wolfgang
 
Reply With Quote
 
 
 
 
Wolfgang Jeltsch
Guest
Posts: n/a
 
      08-30-2003
Wolfgang Jeltsch wrote:

> Hello,
>
> consider the following code:
> #include <iostream.h>
>
> template < typename T >
> int f( T v ) {
> return 0;
> }
>
> int f( int i ) {
> return i;
> }
>
> int main() {
> cout << f( 1 ) << '\n';
>
> return 0;
> }
>
> Is this correct and guaranteed to output 1? Or is there a conflict between
> the template f which can be instantiated to
> int f< int >( int )
> and the function f which is declared as
> int f( int )?
>
> Wolfgang


Additional question: How does overload resolution work if we take
constructors instead of ordinary functions:
template < typename T >
class C {
private:
T v;

public:
template < typename TT >
C( const C< TT > &source );
C( const C &source );
};

I think that for implicit copy operations the explicitely defined copy
constructor is used instead of a template instance with T equal to TT. But
what is done if I initialize explicitely or call constructors explicitely?
Is there a conflict if T and TT are equal?

Thanks in advance!

Wolfgang
 
Reply With Quote
 
 
 
 
Filipe Sousa
Guest
Posts: n/a
 
      08-31-2003
Wolfgang Jeltsch wrote:

> Hello,
>
> consider the following code:
> #include <iostream.h>
>
> template < typename T >
> int f( T v ) {
> return 0;
> }
>
> int f( int i ) {
> return i;
> }
>
> int main() {
> cout << f( 1 ) << '\n';
>
> return 0;
> }
>
> Is this correct and guaranteed to output 1? Or is there a conflict between
> the template f which can be instantiated to
> int f< int >( int )
> and the function f which is declared as
> int f( int )?
>
> Wolfgang


the result is garanteed to be 1 because int f( int ) is more especific than
int f<int>(int)

 
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
SqlDataAdapter, BC30519: Overload resolution failed because no acc =?Utf-8?B?Q2FpbGlu?= ASP .Net 0 09-09-2005 01:57 PM
function overload (not operator overload) Ying-Chieh Liao Perl Misc 3 10-11-2004 11:24 AM
How use the overload of>> (or<<) of a class in the overload of << and >> of another class? Piotre Ugrumov C++ 3 01-25-2004 08:08 PM
overload resolution / integral promotion / standard Alexander Stippler C++ 6 10-30-2003 10:47 AM
Error: Overload resolution failed Eph0nk ASP .Net 0 10-23-2003 09:24 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