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 9025373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:15:25+00:00 2026-06-16T06:15:25+00:00

I have a class called Path that extends std::vector<Square *> , where Square is

  • 0

I have a class called Path that extends std::vector<Square *>, where Square is also a class that I have created. The Path will serve as guide for an Entity traversing a 2D environment. I have need of getting the longest path & shortest path acheivable, and therefore I am looking to find the number of squares between two Squares in a Path. To do this, I feel that it would be beneficial to overload, std::vector<Square *>::push_back(const value_type &__x), although I am not sure what the syntax for that would be. I am currently trying this:

class Path : public std::vector<Square *>
{   //... functional stuff, not relevant. 
    int length;
public:
    push_back(const value_type &__x)
    {   Square *last_square = this->at(this->size() - 1);

        // how do I call super class push_back?
        // however that works, I push back &__x square here.

        Square *most_recent = (Square *)&__x;
        int delta_x = compare_distance(last_square, most_recent);
        length += delta_x;
    };
    int path_length() { return length; };
};

Of course, I suppose I could just write a method inwhich I call push_back for the super class, but I feel like it is more concise to override the function, plus it is good practice for me to learn how to properly override stl functions.

Thanks!

  • 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-16T06:15:26+00:00Added an answer on June 16, 2026 at 6:15 am

    plus it is good practice for me to learn how to properly override stl functions.

    Actually, it’s not.

    STL containers are not meant to be inherited (no virtual method), therefore good practice is to use composition and provide a meaningful interface to your class that use the STL container methods to accomplish its goal.

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

Sidebar

Related Questions

the problem is this... I created a class that extends UIBezierClass called PathExtended, in
I have a class called Path for which there are defined about 10 methods,
I have a class called: ComplexNumber and I have a string that I need
I have a class called Flamethrower which naturally has its own ammunition that is
I have a class called Property that I only need to display a few
I have a class called Trial which has_many results. Now What I want to
I have a class called Account public class Account { public double balance =
I have a class called Metadata, which is declared within the namespace A::B::C ,
I have a class called Property which has nothing but get -methods. All the
I have one class called Global and two other activities. In each activity I

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.