When I try this code, it says "no matching function for..."
Code:template <typename MyType> std::vector<MYType> get( ...elided... ) { ...elided... } int main() { std::vector<std::vector<std::string> ret = get( ...elided... ); }
When I try this code, it says "no matching function for..."
Code:template <typename MyType> std::vector<MYType> get( ...elided... ) { ...elided... } int main() { std::vector<std::vector<std::string> ret = get( ...elided... ); }
Presumably the problem is in the "...elided..." bits. The compiler can only "guess" a type from a template that it gets for a parameter.
Soma
O_oThe compiler can only "guess" a type from a template that it gets for a parameter.
Well, obviously that's not true. I don't even know why I said it.
For a free function used as a parameter to a constructor, this context, it is true.
Soma
Last edited by phantomotap; 04-11-2008 at 08:58 PM.
As Elysia said:
...elided... as well.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
While this is correct, it is irrelevant to the problem. Template instantiations do not overload each other. fn<Foo>() and fn<Bar>() are completely different functions. This is how, for example, lexical_cast, any_cast, and the many variants of get() work in Boost:
Note that in both cases, the arguments to the variants are always the same. Template arguments are sufficient to distinguish functions.Code:template <typename T> T any_cast(const any &a); // Usage: any a(100); int i = any_cast<int>(a); template <int N, typename T1, typename T2, COMPLICATED_PP_METAPROGRAM> complicated_metaprogram get(const tuple<T1, T2, COMPLICATED_PP_METAPROGRAM> &t); // Usage: tuple<int, float, Foo> tpl; int i = get<0>(tpl); float f = get<1>(tpl); Foo foo = get<2>(tpl);
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
*grumble*
My second edit was not accepted...
Anyway, In rare cases the compiler will choose a function based only on the return type. With the right bit of machinery you can force the compiler to examine the target result. If it wasn't for the silly rules regarding when precisely a type is known, even this would not be necessary--explicitly stating the template arguments.
(I thought the OP was asking about how to do that in the case of a constructor.)
Also, are you, the OP, going to at least tell the DEVX forum that you found a solution?
Soma