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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:17:59+00:00 2026-05-20T05:17:59+00:00

There are 2 classes: class A { private: double a1, a2; … }; class

  • 0

There are 2 classes:

class A
{
   private:
        double a1, a2;
   ...
};

class B : public A
{
   private:
        double b1, b2;
};

and a generic container

template <typename Item>
struct TList
{
    typedef std::vector <Item> Type;
};


template <typename Item>
class GList
{
private:
            typename TList <Item>::Type items;

} ;

There 4 containers of objects

GList <A> A1;
GList <B> B1;
GList <A*> A2;
GList <B*> B2;

Are those conversions (up/down) allowed or not:

1] GList <B> B3 = dynamic_cast <GList <B> &> (A1);
2] GList <A> A3 = static_cast <GList <A> &> (B1);
3] GList <B*> B4 = dynamic_cast <GList <B*> &> (A2);
4] GList <A*> A4 = static_cast <GList <A*> &> (B2);

Is there any way how to convert list of objects to list of parent objects and vice versa?

Updated question

And what about reinterpret_cast?

1] GList <B> B3 = reinterpret_cast <GList <B> &> (A1);
2] GList <A> A3 = reinterpret_cast <GList <A> &> (B1);
3] GList <B*> B4 = reinterpret_cast <GList <B*> &> (A2);
4] GList <A*> A4 = reinterpret_cast <GList <A*> &> (B2);
  • 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-05-20T05:18:00+00:00Added an answer on May 20, 2026 at 5:18 am
    GList <B> B3 = dynamic_cast <GList <B> &> (A1);
    

    dynamic_cast works with only polymorphic type. Here GList is not polymorphic. Hence it would not even compile!

    If you make this polymorphic, even then this cast wouldn’t work, since there is no relationship between GList<B> and <GList<A>. They’re like two different unrelated types.

    In fact, they’re related in the same way as GList_B and GList_A are related (suppose, if you define two different classes with such names). Or even better, they’re related in the same way as Java and JavaScript, Car and Carpet are related.

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

Sidebar

Related Questions

if I have these three classes: public class PropertyDouble { private double _value; public
Given the following classes: public class Container { private List<SomeData> list; // public getter
I have the following classes: public abstract class BaseClass { private readonly double cachedValue;
Is there a way to overload base template class functions in derived classes, and
I have 3 classes, two inherit from 1: public class Employee { private virtual
i have three classes. 1.Class:` public class Handler { private String name; private String
There are 2 template classes A and B having 2 private members a1, a2
I have these classes: class Base { ... private: std::vector<X> v; }; class Derived
Are there any other classes provided by php5+ such as the mysqli() class? for
There are many classes having this provider suffix. (Data,membership,modelmetadata,...). When should be a class

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.