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_iterat or,
std::vector<int,std::allocator<int>>::const_iterat or,
int)
object type is: Foo
foo.Bar( v.begin(), v.end(), 42 );
^
I expected the compiler to select the templatized overload.
Cheers! --M 4 2275
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_iterat or, std::vector<int,std::allocator<int>>::const_iterat or, 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
Victor Bazarov wrote: 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_iterat or, std::vector<int,std::allocator<int>>::const_iterat or, 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".
Can you elaborate and perhaps supply a work-around (other than explicit
qualification, preferably).
And it has nothing to do with overloading.
I'm trying to call one of the Foo::Bar() functions based on the
parameter types passed to the function. What should I call it?
Cheers! --M
mlimber wrote: Victor Bazarov wrote: 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_iterat or, std::vector<int,std::allocator<int>>::const_iterat or, 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".
Can you elaborate and perhaps supply a work-around (other than explicit qualification, preferably).
Elaborate? Look in the Standard, 14.8.2.4/9, or in the news archives.
Workaround, eh? Try:
....
template<class I> void Bar(I, I, int);
In that case your 'I' should be 'std::vector<int>::const_iterator', and
you can then extract 'int' from it using 'value_type' or some such.
#include <vector>
using namespace std;
struct Foo
{
void Bar( int, int, int );
template<typename I> void Bar(I, I, int);
};
void Baz()
{
Foo foo;
const vector<int> v( 10u );
foo.Bar( v.begin(), v.end(), 42 );
foo.Bar( 1,2,3 );
}
The code above compiles fine, but it's up to you to see if it suits
your purposes.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Victor Bazarov wrote: mlimber wrote: Victor Bazarov wrote: 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_iterat or, std::vector<int,std::allocator<int>>::const_iterat or, 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".
Can you elaborate and perhaps supply a work-around (other than explicit qualification, preferably).
Elaborate? Look in the Standard, 14.8.2.4/9, or in the news archives.
Workaround, eh? Try:
... template<class I> void Bar(I, I, int);
In that case your 'I' should be 'std::vector<int>::const_iterator', and you can then extract 'int' from it using 'value_type' or some such.
#include <vector> using namespace std; struct Foo { void Bar( int, int, int ); template<typename I> void Bar(I, I, int); };
void Baz() { Foo foo; const vector<int> v( 10u ); foo.Bar( v.begin(), v.end(), 42 ); foo.Bar( 1,2,3 ); }
The code above compiles fine, but it's up to you to see if it suits your purposes.
Ok, thanks. For reference, I used std::iterator_traits to get the
value_type.
Cheers! --M This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Terje Slettebų |
last post by:
To round off my trilogy of "why"'s about PHP... :) If this subject have been
discussed before, I'd appreciate a pointer to it. I again haven't found it
in a search of the PHP groups.
The PHP...
|
by: Dave Theese |
last post by:
Hello all,
I'm trying to get a grasp of the difference between specializing a function
template and overloading it. The example below has a primary template, a
specialization and an overload. ...
|
by: Hendrik Schober |
last post by:
Hi,
I have a problem, that boils down to the following code:
#include <iostream>
#include <typeinfo>
class Test1 {};
class Test2 {};
class Test3 {};
|
by: WittyGuy |
last post by:
Hi,
What is the major difference between function overloading and function
templates?
Thanks!
http://www.gotw.ca/resources/clcm.htm for info about ]
|
by: Jojo |
last post by:
Is there any way to get to the left-hand side of an operator? Consider
the following (this is not meant to be perfect code, just an example of
the problem):
class Matrix
{
public:
int data;...
|
by: zeus |
last post by:
I know function overloading is not supported in C.
I have a few questions about this:
1. Why? is it from technical reasons? if so, which?
2. why wasn't it introduced to the ANSI?
3. Is there any...
|
by: TuxC0d3 |
last post by:
Hi!
I'm diving into the some more ++ specific aspects of c++ (and finally
accepting that c++ is more than "a plus added to c" :), so that means
using namespaces, templates, std::strings, lists,...
|
by: recover |
last post by:
#include <stdio.h>
template<class T>
class TpHello
{
public:
int GetHash(){return 0;}
protected:
private:
T a;
|
by: jakester |
last post by:
I am using Visual C++ 2007 to build the code below. I keep getting
linkage error. Could someone please tell me what I am doing wrong? The
code works until I start using namespace for my objects.
...
|
by: Zach |
last post by:
Consider the following code:
void Test(int i)
{
System.Console.WriteLine("int function");
}
void Test(object o)
{
System.Console.WriteLine("object function");
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |