object oriented design class a and subclass b, how to invoke class b function from class one

  c++, oop

I have a class A and a subclass B, basically, I need to call class A to invoke class B functions to finish the job. I thought I would use a class b pointer points to an array of class B objects, should I declare a class A pointer then invoke class b functions or?

    Class A{
      //constructorA
      //supporting deep copy
      //deconstructor 
      //overloading assignment operator
      //move semantics
      B* object_pointer;
    }
    A::A(unsigned int input){
       object_pointer = new B[size];
       for(int i =0; i < size; i++){
          B object(input);
          object_pointer[i] = object;
          // here we got a class B object array with bunch of B object.
       }
     
    }
    class B{
    //constructor
    //deconstructor
    ......
    function(); 
    }
    B::B(unsinged int input){
       //initialize everything
    }
    //driver
    int main(){
    A test = new A(10);
    // we declare a test object of A
    // which creates 10 B objects
    while(i < 10){
       test[i].function();
    }

However, this returns me a "finished with exit code 139 (interrupted by signal 11: SIGSEGV)" which means somewhere the array out of bounds. I don’t know what’s wrong with this design and logic, and don’t understand why is out of bounding since the size is passed by the input, I knew declare an array of objects needs a non-argument constructor, and the class A constructor is nonargument.

Source: Windows Questions C++

LEAVE A COMMENT