Note that there are some explanatory texts on larger screens.

plurals
  1. POI think I'm confusing name hiding with function overriding
    primarykey
    data
    text
    <p>I'm confused...it seems that both things do the same thing.</p> <p>In this first code, I believe that the derived classes are hiding the function names of the base classes.</p> <pre><code>#include &lt;iostream&gt; using namespace std; class Quadrilateral { public: void greeting() { std::cout &lt;&lt; "i am a quadrilateral" &lt;&lt; std::endl; } }; class Square : public Quadrilateral { public: void greeting() { std::cout &lt;&lt; "i am a square" &lt;&lt; std::endl; } }; class Trapezoid : public Quadrilateral { public: void greeting() { //hides greeting from quadrilateral function std::cout &lt;&lt; "Hi I'm a Trapezoid" &lt;&lt; std::endl; } }; int main() { Trapezoid tz; tz.greeting(); } </code></pre> <p>This seems to have the same exact result: [here they are being overriden because it is virtual in the base class]</p> <pre><code>#include &lt;iostream&gt; using namespace std; class Quadrilateral { public: virtual void greeting() { std::cout &lt;&lt; "i am a quadrilateral" &lt;&lt; std::endl; } }; class Square : public Quadrilateral { public: void greeting() { std::cout &lt;&lt; "i am a square" &lt;&lt; std::endl; } }; class Trapezoid : public Quadrilateral { public: void greeting() { //hides greeting from quadrilateral function std::cout &lt;&lt; "Hi I'm a Trapezoid" &lt;&lt; std::endl; } }; int main() { Trapezoid tz; tz.greeting(); } </code></pre> <p>So I guess I'm just really confused as to...what is the difference? Or what is the point of making it virtual in the base class if it's just gonna have the same effect in this situation?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload