r/Cplusplus • u/onurtuna • Jun 25 '18
Multiple Inheritance in C++
https://medium.freecodecamp.org/multiple-inheritance-in-c-and-the-diamond-problem-7c12a9ddbbec
I have posted that post and will post a second one for virtual inheritance.
Please share your thoughts. I've been improving myself by trying to teach other people.
2
u/TicTacMentheDouce Jun 25 '18
I'm not sure where the issue is in the override exemple, as the snake class already overrides breathe and crawl, so it doesn't matter what reptile does, I don't understand
-2
2
u/2uantum Jun 26 '18 edited Jun 26 '18
the example is, frankly, terrible.
reptile is an animal, so it shouldn't be inheriting from living thing in the first place.
data hiding. none of the methods being overriden are virtual.
even if they were virtual, snake overrides both breathe and crawl so there is no problem.
even if snake wasnt overriding breathe, adding breathe to reptile wouldn't be solvable by virtual inheritance
you basically copied the example from wikipedia and modified it to be worse. if you don't understand the topic, don't write posts trying to teach (confuse) other people.
Two people commented on the post from 7 months ago giving praise helping them understand the issue, but in reality, you confused them.
-4
u/onurtuna Jun 26 '18
You're totally wrong. Please read it again carefully. People writing responses to the post have poor knowledge, so, I can not help them in simple terms.
2
u/2uantum Jun 26 '18
I'm not. Virtual inheritance solves ambiguities caused by having two copies of the base class. It doesn't resolve the problem of having two definitions of the same function. Delete breathe from snake and compile. You'll see.
The only reason you're compiling after you added the virtual keyword is because you have breathe in snake. Virtual inheritance is not solving the problem you're describing in the article with multiple copies of breathe. It's misleading.
2
u/LordDrakken Jun 25 '18
I feel like you didn't finish the blog post. I think you should have shown an example of the virtual inheritance in action like you did for the multiple inheritance scenarios at the beginning.