katang Posted May 21, 2017 Report Posted May 21, 2017 With reference to http://www.cplusplus.com/forum/general/1754/ Is there a syntax variant which allows to put templated member function in the .cpp file? Quote
maehne Posted May 21, 2017 Report Posted May 21, 2017 Simple answer: No. A template is a pattern, which the compiler uses to generate a concrete implementation of a class/function once you use it (i.e., at the place where you either specify the template arguments explicitly or the compiler determines them based on the arguments passed to a function call of a templatized function. Therefore, the compiler has to see at all times the definition of a templated class/function. More information can be, e.g., found in this FAQ: https://isocpp.org/wiki/faq/templates#templates-defn-vs-decl Quote
Roman Popov Posted May 22, 2017 Report Posted May 22, 2017 It is possible if you know expected template parameters in advance. http://en.cppreference.com/w/cpp/language/class_template#Explicit_instantiation This technique is quite often applied in mathematical libraries to reduce compile time. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.