Consider the following code. Is it guaranteed that Derived<int>::foo()
will be instantiated? foo()
is virtual and is called by a non-virtual function of the base class.
#include <iostream>
class Base
{
public:
void bar() { foo(); }
private:
virtual void foo() = 0;
};
template <typename T> class Derived: public Base
{
public:
Derived(T t_) : t(t_) {}
private:
void foo() override { std::cout << t; }
T t;
};
Derived<int> make_obj()
{
return Derived<int>(7);
}
virtual
functions are used and which ones are not used. To be safe, it must instantiate allvirtual
functions. – Fecund