G
greek_bill
I had some code that was failing to compile which amounts to something
like what's shown below. After some digging around, I came across
paragraph 14.1 note 5, which states :
"The top-level cv-qualifiers on the template-parameter are ignored
when determining its type."
Can someone comment on the reasoning behind this? It's probably
covered in something like 'The Design & Evolution of C++' but I don't
have a copy.
Thanks,
Bill
#include <iostream>
#include <typeinfo>
class Bar {};
template<class T>
void Func(T t)
{
std::cout << typeid(T).name() << "\n";
}
template<class T>
void Func(const T& t)
{
std::cout << "const ref : " << typeid(T).name() << "\n";
}
int main()
{
Bar bar;
const Bar& constBar = bar;
Func(constBar);
return 0;
}
gcc gives :
temp.cpp: In function 'int main()':
temp.cpp:24: error: call of overloaded 'Func(const Bar&)' is ambiguous
temp.cpp:7: note: candidates are: void Func(T) [with T = Bar]
temp.cpp:13: note: void Func(const T&) [with T = Bar]
like what's shown below. After some digging around, I came across
paragraph 14.1 note 5, which states :
"The top-level cv-qualifiers on the template-parameter are ignored
when determining its type."
Can someone comment on the reasoning behind this? It's probably
covered in something like 'The Design & Evolution of C++' but I don't
have a copy.
Thanks,
Bill
#include <iostream>
#include <typeinfo>
class Bar {};
template<class T>
void Func(T t)
{
std::cout << typeid(T).name() << "\n";
}
template<class T>
void Func(const T& t)
{
std::cout << "const ref : " << typeid(T).name() << "\n";
}
int main()
{
Bar bar;
const Bar& constBar = bar;
Func(constBar);
return 0;
}
gcc gives :
temp.cpp: In function 'int main()':
temp.cpp:24: error: call of overloaded 'Func(const Bar&)' is ambiguous
temp.cpp:7: note: candidates are: void Func(T) [with T = Bar]
temp.cpp:13: note: void Func(const T&) [with T = Bar]