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

  • Home
  • SEARCH
  • 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 8753021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:20:50+00:00 2026-06-13T13:20:50+00:00

Here is the issue with my code I got a parent class Shape and

  • 0

Here is the issue with my code

I got a parent class Shape and a child class Square

struct Point
{
    int x,y;
};

class Shape
{
private:
    string name;

public:
    void setName(string);
    string getName();
    virtual void setVerticlePoint() { };
    virtual Point getVerticlePoint();
};

Below is Square.cpp

class Square: public Shape
{
private:
    Point verticlePoint[4];

public:
    int noOfVerticles() const { return 5; }
    void setVerticlePoint();
    Point getVerticlePoint();
};

void Square::setVerticlePoint()
{
    int xData,yData;

    for(int i=0; i<4; i++)
    {
        cout << "Please enter x-ordinate of pt." << i << " :";
        cin > xData;
        cout << "Please enter y-ordinate of pt." << i << " :";
        cin >> yData;
        verticlePoint[i]->x = xData;
        verticlePoint[i]->y = yData;
    }
}

So at main.cpp , i did this

int main()
{
    Shape *point[5];
    Point vertic`lePoint;
    Square *cro = new Square();

    // some codes in between

    // now i prompt for verticle point

    shape[0] = squr;

    //assuming myShape & myType is some string value
    shape[0]->setName(myShape);
    shape[0].setType(myType);

    //here i will be prompt to key in 4 times of X & y Ordinate of the verticle point
    shape[0]->setVerticlePoint();

    //Now the issue is i need to retrieve back my verticle point that i store in shape[0].

    //here no issue
    cout << "Get Name: " << shape[0]->getName() << endl;
    cout << "Get Data:"  << shape[0]->getType() << endl;
    //the top 2 works

    //this is the issue
    verticlePoint = shape[0]->getVerticlePoint();
    cout << sizeof(verticlePoint);
    //it output as size 8 , no matter which shape i use, i got other shapes with different verticle point.

    return 0;
}

Issue is :

How do i retrieve the verticlePoint[array] (e.g for square is verticlePoint[4], how do i retrieve the Point into a variable in main class, and then use a for loop to call out the x,y of shape[0] for verticlePoint[0] to verticlePoint[4]

Thanks for all help!

  • 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-13T13:20:51+00:00Added an answer on June 13, 2026 at 1:20 pm

    Apparently you want to return a different number of points depending on the shape. To do this you could for example use std::vector<Point> as return type… for example:

    class Shape
    {
    private:
        string name;
    
    public:
        void setName(string);
        string getName();
        virtual void setVerticlePoint() { };
        virtual std::vector<Point> getVerticlePoint();
    };
    

    then in square, for example, you would return a vector of 4 points…

    std::vector<Point> Square::getVerticlePoint()
    {
        return std::vector<Point>(verticlePoint, verticlePoint+4);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got a bit of issue here. Vehicle is parent class Car and Motorcycle
I got some weird issue here. The code is as below NSMutableString *unicodeString =
Here is my issue. I have an ASPX web site and I have code
What is the issue with this code? Here we have two files: classA.h and
Here is the my python code using BeautifulSoup. The main issue is with the
i have this quick issue please. I have this code here which permits me
i have an issue with uploading multiple files to disk. here is my code.
The following code has concurrency issues. Here inDegVec is a global int * ,
I have one issue with retrieval Parent/Child relationship of type Folder Hierarchy Ideally, in
I'm running a weird issue here. I have code that makes jquery ajax calls

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.