can we declare a function templatein a normal class without a template class, or should it always be inside template class?
template
template class
can declare a template function in a normal class with a template class
Yes we can. for instance
class demo { public: template <typename T> void func(const T& x) { //do stuffs } }; int main() { demo d; d.func<int>(5); }
works great
Yes, you can have template functions in non-template classes, for example:
struct X { template<class T> void f(const T& t) { // ... } };
, , , . , , -
Source: https://habr.com/ru/post/1774887/More articles:Problem installing PHPUnit on Windows using PEAR and without PEAR - phpunitDoes the ASP.NET website publish any additional security benefits? - securityC # Entity Framework: how to update record and change foreign key link? - c #Cycle counter in Java API - javaWhat could be the best data structure for storing recursive, multi-valued and repeating paired data with a key? - c ++What is the correct way to use partial view models in ASP.NET MVC2? - model-view-controllerSite Under Construction page for asp.net - asp.netWhat are the pros and cons of this class definition style? - c ++A non-OO PHP design pattern, the PHP pattern best suited to this situation - designwrite C ++ the format_string function for formatting, for example sprintf std :: string - c ++All Articles