i dont understand how templates can cause code bloat in a binary file...does anyone happen to have an easy to understand explanation of this?
lochnessmonster
0
Junior Poster
Recommended Answers
Jump to Post#include <iostream> template <typename T> void display(T value) { std::cout<< value <<'\n'; } int main() { int a = 123; double b = 123.456; display(a); display(b); }
This causes the template to be instantiated twice, once with each unique signature:
#include <iostream> void display(int …
Jump to PostTemplates are designed to generate code at compile time. Due to this design, the only way they will ever contribute to the ultimate size of a binary is by making it larger. Think of templates as incomplete sections of code that get filled in at compile time. So if you …
All 5 Replies
Narue
5,707
Bad Cop
Team Colleague
lochnessmonster
0
Junior Poster
Narue
5,707
Bad Cop
Team Colleague
gerard4143
371
Nearly a Posting Maven
L7Sqr
227
Practically a Master Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.