Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > value vs. const...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 8 Topic 43093 of 47561
Post > Topic >>

value vs. const ref, char* vs char[4] - part 2

by Rick <CubsNo1@[EMAIL PROTECTED] > Feb 4, 2008 at 02:58 PM

Is the following appropriate behavior?  It certainly isn't what I
expected.


#include <iostream>

using namespace std;

template<typename T> bool fun(const T& value) {
    cout << "In fun(const T&);" << endl;

}

template<typename T> bool fun(T value) {
    cout << "In fun(T);" << endl;

}

int main(int argc, char** argv) {
    fun(static_cast<const int&>(10) );

}

$ CC test.C
"test.C", line 14: Error: Overloading ambiguity between
"fun<int>(const int&)" and "fun<int>(int)".
1 Error(s) detected.
$
$
$ g++ test.C
test.C: In function `int main(int, char**)':
test.C:14: error: call of overloaded `fun(const int&)' is ambiguous
test.C:5: note: candidates are: bool fun(const T&) [with T = int]
test.C:9: note:                 bool fun(T) [with T = int]
$

I would have said that if I tell the compiler explicitly that I want a
const int&, there is no ambiguity.  Something in the C++ standard
apparently says that this is correct behavior, but it seems wrong to
me.

                    Regards,

                    Abraham
 




 8 Posts in Topic:
value vs. const ref, char* vs char[4] - part 2
Rick <CubsNo1@[EMAIL P  2008-02-04 14:58:35 
Re: value vs. const ref, char* vs char[4] - part 2
"Bo Persson" &l  2008-02-05 00:56:43 
Re: value vs. const ref, char* vs char[4] - part 2
diligent.snail@[EMAIL PRO  2008-02-04 16:32:47 
Re: value vs. const ref, char* vs char[4] - part 2
Rick <CubsNo1@[EMAIL P  2008-02-05 10:29:07 
Re: value vs. const ref, char* vs char[4] - part 2
"Bo Persson" &l  2008-02-06 20:49:32 
Re: value vs. const ref, char* vs char[4] - part 2
Andrey Tarasevich <and  2008-02-06 16:50:42 
Re: value vs. const ref, char* vs char[4] - part 2
Andrey Tarasevich <and  2008-02-06 16:54:20 
Re: value vs. const ref, char* vs char[4] - part 2
Rick <CubsNo1@[EMAIL P  2008-02-07 07:20:11 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Sep 7 3:54:33 CDT 2008.