We have following class definition
template<typename T>
class Klass {...}
and we also have below two instantiations
Klass<int> i;
Klass<double> d;
how many copies of Klass' methods are generated by the C++ compiler? Can somebody explain it? Thanks!
Klass
isn't a type, so it doesn't make sense to talk of Klass
's methods. Kalss<int>
is a type with it's own methods, and so is Klass<double>
. In your example there would be one set of methods for each type.
Edit in real life, it isn't as simple as that. The question of the actual existence of the methods also depends on other factors, see @KerrekSB's answer to this question.