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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:10:42+00:00 2026-06-18T08:10:42+00:00

Basically I’ve a class A and a class B : public A . And

  • 0

Basically I’ve a class A and a class B : public A.

And I’d like to cast a std::shared_ptr<std::vector<A*> to a std::shared_ptr<std::vector<B*>

The problem is std::vector<B> doesn’t inherit from std::vector<A>, and the smart_ptr neither. So I do a horrible cast:

  std::shared_ptr<VectorA> vector_a = * ((std::shared_ptr<VectorA>*)&vector_b);

The code compiles and runs there, but it is safe?
http://liveworkspace.org/code/3dQTz1$0

  • 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-18T08:10:43+00:00Added an answer on June 18, 2026 at 8:10 am

    Strictly speaking the dereferencing operations should succeed. Both vectors are pointer containers, so casting one to another, whilst unacceptable for production code, will still use the same dimensions and alignment.

    C++ provides rich abstractions to avoid these shenanigans though, it would be better to populate the vector of derived objects as pointers to the base class.

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

Sidebar

Related Questions

Basically, I have slider which I would like to be triggered from menu too.
Basically, I have something like the following: public string SomeDBMethod(string server, string dbName, string
Basically from C++ FAQ I learned that: A virtual function allows derived classes to
Basically, from the form that I made I send customer_name and with this code
basically: public delegate void RecvCommandHandler (ChatApplication sender, byte[] content); event RecvCommandHandler[] commands = new
Basically I'm just looking for a 'SelectedItemTemplate' in the SL3 ComboBox. Unfortunately, that doesn't
basically i'm attempting to target elements only within the parent db_update div class of
Basically I have code that initialises the database in a DatabaseHelper extended class (see
Basically like the opposite of Math.pow() . I want a function which can be
Basically what i am trying to do here is to read from the table

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.