In this post we will write a C++ program to use destructor. User will enter the radius of a circle and using the destructor program will print the radius of circle.

C++ program to use destructor


C++ program to use destructor.

#include<iostream>
#include<conio.h>

class circle
{
    private:
        int radius;
    public:
        circle()
        {
            radius = 0;
        }
        ~circle()
        {

        }
        circle(int m)
        {
            radius = m;
        }
        dis()
        {
            std::cout<<"The radius is = "<<radius;
        }
};

int main()
{
    system("cls");

    int n;

    std::cout<<"Enter the radius = ";
    std::cin>>n;
    circle clr(n);
    circle clr1(clr);
    clr1.dis();

    getch();
    return 0;
}



Output

Enter the radius = 6
The radius is = 6