0
#include <iostream>
using namespace std; 

class Base { 
public: 
    ~Base() { 
        static int count = 0; 
        cout << "...calling destructor " << ++count << endl;
    }
};

#include <typeinfo> 

int main () { 

    Base b0; 
    Base b1 = Base(); 
    Base b2();

    cout << typeid(b1).name() << endl;
    cout << typeid(b2).name() << " : " << b2 << endl;

    return 0;
}

OUTPUT

4Base
F4BasevE : 1
...calling destructor 1
...calling destructor 2

In the above code, I am expecting to create three objects of type Base which has no user-defined constructors.

As is obvious in the output, the destructor is invoked only twice. Inspecting object b2 using typeid, emits the strange F4BasevE string (as opposed to 4Base).

Questions:

  1. What does F4BasevE mean?
  2. 1 appear when trying to print b2 - what does that mean?
  3. What constructor do I have to define in the class to be able to create object b2 the way it is defined?
lifebalance
  • 1,846
  • 3
  • 25
  • 57

0 Answers0