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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:32:23+00:00 2026-06-04T19:32:23+00:00

Here is the problem — I have two classes like this: class A {

  • 0

Here is the problem — I have two classes like this:

class A
{
  //some fields and methods 
   void niceMethod();
};

class B : public A
{
   void niceMethod();
};

class C : public A
{
   void niceMethod();
};

and function

void myFunc(A** arrayOfABC);

//Double * is to notice that I am going to modify the argument.

And I want to do:

(*arrayOfABC)[i].niceMethod();

in my function, getting different things done when I pass array of Bs or Cs to function.

But then I try to call it like

 B* bees = NULL;
    myFunc(&bees);

I have “Argument type of B** is incompatible with parameter of type A**”.

I know that I can pass B or C as A to functions like f(A), but what’s wrong with pointers?

  • 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-04T19:32:25+00:00Added an answer on June 4, 2026 at 7:32 pm

    The compiler is right, it is indeed incompatible. Consider this:

    B* bees = new B[2];
    myFunc(&bees); // Imagine that it's allowed
    

    Now inside myFunc you do this:

    void myFunc(A** arrayOfABC) {
        // This is OK:
        arrayOfABC[0] = new C();
    }
    

    This should be allowed, because C extends A. However, upon return from myFunc your bees would contain a C, which is not good.

    To fix this, create an array of A*, and populate it with pointers to B.

    P.S. Don’t forget to make niceMethod virtual, otherwise it’s not going to work the way you expect.

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

Sidebar

Related Questions

<div id=updatePlayerList> //some content </div> my code is like this <script> $('#updatePlayerList').fadeOut(1000); </script> Problem
Maddening problem here. When my page loads: <body onload=getClientDateTime();> It runs this function: document.getElementById('ClientDateTime').value=hello
I Have a problem here. i wanna to test my parser result. i have
need some help here My problem is, my app starts with a single view,
I have a problem here. My Zend_Forms do not render in view script. Via
I have a problem here I can't solve. I have a database of houses
enter code here My problem is this: in this database the junction table contains
I've got some problem with my function and don't know how to solve this
PROBLEM: Here's the code: import matplotlib.pyplot as plt plt.bar([1,2],[5,4]) plt.title('this is a very long
hi all i have implemented code as shown in the below here problem is

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.