In the following program:
#include <iostream>
using namespace std;
class first{
public:
first(){cout << "FIRST" << endl;}
};
class second: public first{
public:
second(){cout << "SECOND" << endl;}
};
int main(){
second obj();
return 0;
}
Nothing is outputed.When instantiating an object of second
, both constructors are called, so why is there no output?
Turns out, that if in the main function the command is: second* pointer = new second();
the output is:
First
Second
Why does that happen?