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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:53:44+00:00 2026-06-12T03:53:44+00:00

I have two classes, A and B Class B has a private member variable

  • 0
  • I have two classes, A and B
  • Class B has a private member variable which is a constant dynamically
    sized array of object A
  • One of the constructors for class B will take a constant reference to
    a Class A object which will be used to set the array in class B

class B:

class B
{
  private:
    const A** theArray;
  public:
    B(const A&);
};

B::B(const A& newA)
  : theArray(newA) //<-- ??
{
}

When I try to compile the program, I get an error saying “cannot convert from ‘const A’ to ‘const A **’ “

How would I pass an object into the member initializer list so I could make an array out of them?

edit 1:
This is for a comsci class assignment. We’re learning about classes right now and the assignment has us creating three separate constructors for this particular class (a copy constructor; one to add a new A object into ‘theArray’ in class B; and a constructor that add the first A object into ‘theArray'(this is the constructor in question).)

The idea is that you call the third constructor in the list to create an object. Then if you want to add another A object to the array you would call the second constructor. Then if you wanted a copy of the object you would use the copy constructor.

  • 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-12T03:53:46+00:00Added an answer on June 12, 2026 at 3:53 am

    when I try to compile the program I get an error saying “cannot convert from ‘const A’ to ‘const A **’ “

    Then, the first thing you must do is understand the compiler error. What is trying to say the compiler?

    In the B constructor you’re initializing a member of the type const A ** with a given parameter of the type const A &; they aren’t of the same type and this is why the compiler is complaining.

    So, what to do to fix it?

    You must make the B constructor to take the same type of the member variable as argument.

    class B
    {
    private:
        const A** theArray;
    public:
        B(const A**);
    };
    
    B::B(const A** newA)
        : theArray(newA) //<-- They're of the same type: no problem.
    {
    }
    

    But you must ensure that the calls outside the class matches the constructor definition.

    But instead of it, I advise to revise the design, you’re sure that naked pointers is the only solution to your problem? You must answer this questions in order to improve the class B:

    • Where the dynamic memory is created an where is destroyed?
    • The class B takes the ownership of the given A**?

    If the class B will be the owner of the dynamic memory, you must think about creating and destroying the theArray inside the class B itself not outside.

    If the class B will not be the owner of the dynamic memory, you must be very careful about the memory: The memory pointed by theArray will be destroyed after of before the class B? in other words, could be a class B instance with memory pointed by theArray already deleted? In this case, smart pointers could be a good help.

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

Sidebar

Related Questions

I have a class which has two HashSet<String> collections as private members. Other classes
I have two classes, class A and class B. Class A has a mission
Suppose we have two classes: class Base { private: int x; public: void f();
I have two classes, Car and Person. Car has as one of its members
I have two ActiveRecord classes class Product : ActiveRecordBase<Product> { private IList<Usage> _usages =
I have two closely related classes which I'll call Widget and Sprocket. Sprocket has
I have two classes, WebServiceRequest and OrderRequest. Each class has properties. OrderRequest inherits from
I have two classes: Action class, that has a method for executing VBScript files,
I have defined two classes below: public class junk { private BigInteger a =
I have two classes: public class Article { private ISet<IdentNumber> identNumbers = new HashedSet<IdentNumber>();

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.