0
  1. I am trying to solve a quiz and came across this question.
    Please explain what happens internally that leads to this Output

    class B;
    
    class A { 
        friend class B;
    
        public: 
        ~A() {
            B boj();
            cout << "object A destructor " << endl;
        } 
    }; 
    
    class B  { 
        public: 
        ~B() { cout << "object B destructor " << endl; } 
    }; 
    
    int main() { 
        A a;
        A aobj(); 
        B bobj();
    }
    

    The output is:

    Object A destructor

  2. I am trying to create a program where a user enters if he wishes to add another record, and if yes then create a new object for that record.

    So if I am including constructors, then how do I create a new object every time the user wants?

    (If I give a predefined size to the array of object, then constructor will be called, say 50 times and initialize all 50 objects, while the user may only want to enter less).

GSerg
  • 76,472
  • 17
  • 159
  • 346

1 Answers1

0

First, a is constructed. Then, a is destroyed.

The final two declarations in main, and the declaration inside ~B(), are all local function declarations and therefore don't "do" anything.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055