If that's the actual example of the book, I don't think it's a good book.
> string GetName()
no const-correct, can't be called on const object
> virtual string MakeSound() = 0;
has a virtual member function, but no virtual destructor
> void operator = (const Dog& D)
¿what for? it was already defined (implicit) and now doesn't have return value
> void GetNameAndMakeSound(T& theAnimal)
function in line 69, never used
note that it ask for a reference but shouldn't modify the parameter (see also: const-correctness)
> T m_animal;
> AnimalTemplate(T animal) : m_animal(animal) {}
member of AnimalTemplate, it's a copy of the object passed to the constructor
¿why a copy?
> Dog dog = Dog("Bulldog");
c++ it's not so stupid that you need to repeat every thing that you need (unlike java)
although it is a valid initialization, these are preferred
1 2 3 4
|
Dog dog("Bulldog");
Dog dog{"Bulldog"};
auto dog = Dog("Bulldog");
auto dog = Dog{"Bulldog"};
|