TITLE: errors and template instantiations (Newsgroups: comp.lang.c++.moderated, 16 Dec 98) CLELAND: "James A. Cleland" >> It would appear that, when defining a parameterized type, methods of >> that type that aren't used in a dependant implementation aren't >> subject to function/method resolution. FLAYVAH: flayvah@my-dejanews.com > AFAIK, modern C++ compilers only instantiate member functions of > template classes that are actually used. I assume this is an > optimization ... CLAMAGE: Steve Clamage No, it is a requirement of the language definition. Otherwise, it would make writing general templates very difficult. You couldn't define an operation for a template class unless the implementation worked for every type of interest -- even when the operation made no sense for the type. You would have to write many more specializations, or have slightly different versions of general templates for different categories of types. Instead, the rule is that no template is instantiated unless it is used, and apparent errors in templates that are not instantiated are in fact not errors. For example, suppose you templatize a class on character types, and include conversion functions between wide characters and multibyte characters. If the class is instantiated on type char, the conversion functions won't compile. But they won't be compiled unless somone incorrectly tries to use a wide-character function on a char.