- Parent constructor is called
- Child constructor is called
- Child destructor is called
- Parent destructor is called
Source Code
Source.cpp
#include "Parent.h"
#include "Child.h"
#include <iostream>
int main()
{
Child* testChild = new Child();
testChild->~Child();
int endInput;
std::cin >> endInput;
return 0;
}
Parent.h
#pragma once
#include <iostream>
class Parent
{
public:
Parent();
~Parent();
};
Parent.cpp
#include "Parent.h"
Parent::Parent()
{
std::cout << "Parent Constructor Called" << std::endl;
}
Parent::~Parent()
{
std::cout << "Parent Destructor Called" << std::endl;
}
Child.h
#pragma once
#include "Parent.h"
#include <iostream>
class Child : Parent
{
public:
Child();
~Child();
};
Child.cpp
#include "Child.h"
Child::Child()
{
std::cout << "Child Constructor Called" << std::endl;
}
Child::~Child()
{
std::cout << "Child Destructor Called" << std::endl;
}
Console Output
No comments:
Post a Comment