I am working through Sam's Teach Yourself C++ For Linux In 21 Days. Yes, it's an OLD book (Copyrighted 2000) but I HAVE it and the concepts seem relevant. I'm having a problem. I can't figure out this one. Today,I'm typing in a program from the book, but it's not giving me the correct output. pDog->Speak SHOULD be outputting Woof!, not Mammal speak! Why isn't it working?
foo.cpp|20 col 12| warning: 'Dog::Speak' hides overloaded virtual function [-Woverloaded-virtual]
foo.cpp|10 col 20| note: hidden overloaded virtual function 'Mammal::Speak' declared here: different qualifiers (unqualified vs 'const')
foo.cpp|20 col 26| error: non-virtual member function marked 'override' hides virtual member function
foo.cpp|10 col 20| note: hidden overloaded virtual function 'Mammal::Speak' declared here: different qualifiers (unqualified vs 'const')
its not that old books are totally wrong, they usually are not, so long as you understand that they can be wrong in places (due to language changes) and they can (and often do) present things that we have better ways to solve (language has added a ton since then).
It isnt that old. 3/4 of my books date from the late 80s/early 90s, because I never throw anything away I guess...
the stuff you are doing here is pretty much unchanged.
PS It doesn't make (common) sense to go to all the trouble of designing an inheritance scheme and then declaring a Mammal and then creating it as a new Dog.