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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:54:00+00:00 2026-06-08T23:54:00+00:00

1.So I have: Class A; Class B : public A; Class C : public

  • 0

1.So I have:

Class A;

Class B : public A;

Class C : public B;

2.And a vector of pointers of type B:

vector<B*> vec;

3.Then:

C* ptr = new C();

vec.push_back(ptr);

So the question is, it is reliable to use std::find like this?

std::find(vec.begin(), vec.end(), prt);

Also, is it fine to do search using this-> pointer?

std::find(vec.begin(), vec.end(), this); //inside of a type C object

Thanks in advance.

  • 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-08T23:54:01+00:00Added an answer on June 8, 2026 at 11:54 pm

    Yes, this is safe since there is a well-defined comparison (==) between pointers to objects in a type hierarchy. Even though the actual value of the pointers may differ after a conversion to a base class type (often the case with multiple inheritance), the runtime is required to adjust for that so that comparisons between those pointers still yield the correct result.

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

Sidebar

Related Questions

Let's say i have 2 classes: class Class1 { public: std::vector<CustomClass3*> mVec; public: Class1();
I have a std::vector of some class of the form class A{ public: A():i(someNumber){}
I have class A: public B { ...} vector<A*> v; I want to do
I have the code: class Vector3D : public Vector{ protected: Point3D * start; Point3D
I have the following existing classes: class Gaussian { public: virtual Vector get_mean() =
class A { } class B : public A { } std::vector<B*> things; void
I have this code to represent bank: class Bank { friend class InvestmentMethod; std::vector<BaseBankAccount*>
I have a class that adapts std::vector to model a container of domain-specific objects.
If I have: class Test { private Vector2 v; public Vector2 Velocity { get
I have class with back reference: public class Employee : Entity { private string

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.