DEV Community

A Beginners Guide: Polymorphism, Virtual Functions, and Abstract Classes With C++

Gyau Boahen Elvis on August 09, 2023

Polymorphism Polymorphism comes from two words: Poly which means many and Morph which means form. Polymorphism as a word simply means ma...
Collapse
 
pauljlucas profile image
Info Comment hidden by post author - thread only accessible via permalink
Paul J. Lucas
dogType::dogType(string name, string breed){
    PetType::PetType(name);
    this->breed=breed;
};
Enter fullscreen mode Exit fullscreen mode

This is wrong. It won't even compile. You must use mem-initialization as you did in your previous example to initialize base classes. You should use it for data members otherwise you pointlessly default initialize members first only to assign them immediately afterwards. So the code is very much not the same.

And you should be passing string by const& otherwise you make pointless copies of the string.

Collapse
 
gyauelvis profile image
Gyau Boahen Elvis

Yeah

I just realized. I will make the correction right now. Thank you😊

Some comments have been hidden by the post's author - find out more