When you use a template with numerous methods (like vector) and compile your code, will the compiler discard the code from the unused methods?
When you use a template with numerous methods (like vector) and compile your code,
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A template is not instantiated unless it is used, so there is actually no code to discard.
The standard says (14.7.1/10)
So if you can avoid making the template’s member functions virtual, the compiler will not generate any code for them (and that might work for virtual functions as well, if the compiler is smart enough).