class P
{
};
template< typename P >
class C : public P
{
public:
void f()
{
P::f();
}
};
int main() {
C<P> c1;
return 0;
}
Just in case my question leaves any room for misunderstanding, here is a code example. If C
was not templated but inherited from P
directly, then the sample would fail to compile because clearly function f()
attempts to call a function on base class P
which is non-existent.
However if C
is templated then this is only picked up if f()
is actually called.
I'd like to know why there is this difference. In both instances f()
would be dead code and stripped anyway, yet the program is ill-formed in the non-template scenario.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…