Is non-template member function in class template generated only once in executable?

  Kiến thức lập trình

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.

5

LEAVE A COMMENT