However, I get a compiler error saying that I cannot initialize the string to -1.0, which means that the compiler is trying to call base :: get () when I call d.print ().
No, this compiler error means that the compiler is trying to create an instance of base<std::string>::get() , which it must execute because derived uses base<std::string> as the base class. Just because you are not calling a function does not mean you cannot. You can still call base<std::string>::get() directly.
You created an instance of base<std::string> and used it as a base class. Since base<std::string>::get() is a virtual function, it is considered "used" because you use base<std::string> as a base class. Since it is used, it must be created. Therefore, the compiler should and will try to compile the function.
And since std::string cannot be implicitly built from float, compiler errors occur due to a failed template replacement.
source share