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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:17:27+00:00 2026-06-09T19:17:27+00:00

class A{}; class B : A{}; void func(A* p) { B* p2 = p;

  • 0
class A{};

class B : A{};

void func(A* p)
{

      B* p2 = p; // Error

}
  • 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-09T19:17:29+00:00Added an answer on June 9, 2026 at 7:17 pm

    Your code has several oddities.

    1. You use private inheritance. In private inheritance you will not be able to convert to a derived class ever when you are not inside the class scope itself.
    2. Even if you would inherit publicly, you will need at least one virtual function (and that should be the destructor) in the base class to use dynamic_cast.
    3. Chances are you are doing something wrong when you need a lot of down-casts. You should probably rethink your design or usage of the provided API.

    Typically, things would look like this:

    class A { 
    public:
      virtual ~A() {}
    };
    
    
    class Derived : public A {
    
    };
    
    void func(A* a) {
      if(Derived* d = dynamic_cast<Derived*>(a)) {
        // yeah, a is of type derived
      } else {
        // a is not of type Derived 
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public class Demo { public void When(Func<Person, bool> condition) { if (!condition) { Log.Info(Condition
I have a class: class A { public: virtual void func() {…} virtual void
I saw the following snippet code: class Foo { public: void virtual func() throw
class Parent{ }; class Child: public Parent { } void Func(Parent*& param) { }
include stdafx.h #include <iostream> using namespace std; class Foo{ public: void func() { cout<<Hello!!<<endl;
##A.hh template<class T> void func(T t) {} template<> void func<int>(int t) {} void func2();
Consider the following : class Abstract { public: virtual void func() = 0; };
Given this code: class X { public: template< typename T > void func( const
The following gives me a couple compile errors: error C2995: 'void A<T>::B<Q>::func(void)' : function
class A { void F() { System.out.println(a); }} class B extends A { void

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.