#Template instantiation
29 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For more information use !howto ask.
well... when you call the function
foo(vp);
this does not always mean that the type T will be substituted with decltype(vp) which here is void*, C++ is trying to find the best match for the template, and here the best match is T = void
if you really want to be explicit and ban any form of template deduction or guessing, you can do this instead:
foo<void*>(vp);
and now the type T will be guaranteed to be void* but then T* will be void** and your vp parameter cannot be inplicitly converted to void** so you will get a compilation error, you gotta use &vp instead
the automatic template deduction is a feature of C++11, C++98 did not have that
so in C++98 you were forced to do shit like
int arr[] = {2,5,4,7,1};
std::sort<int*>(arr, arr+5);
there should be a long set rules for arguments match im guessing, my brain just directly substituted types

yes, template deduction guidelines in cppreference
very long, very boring
learn templates by writing code instead pls
oh and
i think the main thing you need to keep in mind is the above
no, honestly
well...
as you begin learning more about templates you will probably hit this question one day
the approach I use is
write a compilation error in the function
compile
and in the compilation error it show all of the templates substituted 🙂
@broken ridge Has your question been resolved? If so, run !solved :)
!solved