Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8766439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:33:08+00:00 2026-06-13T16:33:08+00:00

I have this Parent Class call Shape (ShapeTwoD.cpp) He got 2 Child Class 1

  • 0

I have this Parent Class call

Shape (ShapeTwoD.cpp)

He got 2 Child Class

1 is Rectangle (Rectangle.cpp)
1 is Square (Square.cpp)

There this variable call area declare at Rectangle & Square , but not at Shape(the parent)

So i was trying to sort by area ascending, however area can be access by

class->getArea();


vector<ShapeTwoD*> myVector;

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

myVector[arrayCount] = new Rectangle();
myVector[arrayCount].setWidth(inWidth);
myVector[arrayCount].setHeight(inHeight);
myVector[arrayCount].computeArea();

arrayCount ++;

//done record width , height and then compute area of the shape

Assuming myVector now Contains about 2 Rectangle and 1 Square

Now I want to sort them by area ascending.

But my getArea() function is only available at child class.

If i try do this

sort(myVector.begin(),myVector.end(),funcAreaSort);

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)

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

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

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.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T16:33:09+00:00Added an answer on June 13, 2026 at 4:33 pm

    1) Make the compare function take ShapeTwoD* as parameters, and have a virtual getArea method in the base class, which you override in the children.

    2) Make the method getArea const:

    int getArea() const;
    

    because it logically makes sense & so that you can call it on const objects.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In objective-C I want to have a child class call or invoke a parent's
I have this entities: public class Parent: AllDependant { /*Properties goes here*/ } public
I have a base class Parent like this: using System; using System.Collections.Generic; using System.Text;
Supposed I have two classes like this: public class Parent { public string Id
I have written this clone method for when the parent of the Employee class
I have a model that looks something like this: public abstract class Parent {
I have the following structure: class foo(object): class bar(object): def __init__(self, parent): self._parent=parent #this
Suppose I have this table parent | child 1 2 1 3 2 4
I have a path like this: parent/child/reply How do I use PHP to remove
I have this code that uses a template parent class A that has one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.