Calling Sort on Main Against Different Child Class Value
<p>I have this Parent Class call</p>

<pre><code>Shape (ShapeTwoD.cpp)
</code></pre>

<p>He got 2 Child Class</p>

<pre><code>1 is Rectangle (Rectangle.cpp)
1 is Square (Square.cpp)
</code></pre>

<p>There this variable call area declare at Rectangle &amp; Square , but not at Shape(the parent)</p>

<p>So i was trying to sort by area ascending, however area can be access by </p>

<pre><code>class-&gt;getArea();


vector&lt;ShapeTwoD*&gt; myVector;
</code></pre>

<p>//during the period of recording data like width ,height to the shape. </p>

<pre><code>myVector[arrayCount] = new Rectangle();
myVector[arrayCount].setWidth(inWidth);
myVector[arrayCount].setHeight(inHeight);
myVector[arrayCount].computeArea();
</code></pre>

<p>arrayCount ++;</p>

<pre><code>//done record width , height and then compute area of the shape
</code></pre>

<p>Assuming myVector now Contains about 2 Rectangle and 1 Square</p>

<p>Now I want to sort them by area ascending.</p>

<p>But my getArea() function is only available at child class.</p>

<p>If i try do this</p>

<pre><code>sort(myVector.begin(),myVector.end(),funcAreaSort);
</code></pre>

<p>I not sure where to create funcAreaSort , next is how do i send in child area , assuming if they are same shape class(rectangle against rectangle) or different shape class (rectangle against shape)</p>

<p>how i create a boolean operator overload that can compare by getArea() then see which is better return a.getArea() > b.getArea() and sort myVector</p>

<p>Question is Where do i create those function I was thinking of making it a free method at main.cpp but i fail getting the thing sort and compile with error like qualifier error</p>

<pre><code>error: passing 'const shapeTwoD' as 'this' argument of 'virtual double shapeTwoD::getArea()' discards qualifers.
error: passing 'const shapeTwoD' as 'this' argument of 'virtual double shapeTwoD::getArea()' discards qualifers.
</code></pre>
