On Apr 11, 10:46 pm, Ian Collins <ian-n...@hotmail.com> wrote:
Rob wrote:
I tried that and it still does not compile. I think it's because the
overloaded methods that will be created for the templated function
only differ by return type and not by args (the args are always the
same). Am I correct in that overloaded methods must differ in args?
Yes.
--
Ian Collins.
Uh, I beg to differ. I have used similar templated functions
frequently with no trouble. Think about boost::lexical_cast for
example. That works just fine even if you try to cast a string to an
int and also a string to a double. But by the logic of this thread
that should be illegal because the overloaded methods created by the
template wouldn't differ in their arguments.
I also just compiled this program in gcc and it worked fine for me.
#include <vector>
#include <string>
using namespace std;
template <typename T>
vector<T> get(int c)
{
return vector<T>();
}
int main()
{
vector<vector<string> > ret1 = get<vector<string> >( 0 );
vector<string> ret2 = get<string >( 0 );
}
What exactly are you trying to compile that isn't working?
-Davis
You're a genius!! The problem was in what I was specializing to. I'd