Example:
template<typename T>
class A {
void f() { std::cout << "f";}
};
...
A<int> a;
A<double> a;
Is f generated once or multiple times (once for each template instantiation) in a final binary after compilation and linking? I can't seem to find this rule in the standard. AI says it's generated only once, but I don't trust it enough.
The standard doesn't describe the structure of a program "in a final binary after compilation and linking".
There can be any number of copies of instructions that correspond to outputting the character f to standard output. There could be 0, 1, or 2 symbols exported corresponding to those functions.
What is required is that the pointer values &A<int>::f and &A<double>::f compare unequal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With