In my C++ program, I'm working with destructors and constructors in classes. For no apparent reason, when I initiate the constructor, the destructor is also run. This is the function code:
#include "Foo.h"
int main()
{
Foo f;
return 0;
}
The normal output should be just "this is the ctor"
, but for some reason it prints both the constructor output and the destructor output ("this is the ctor this is the dtor"
). There is no reason for it to run the destructor because I didn't delete the object.
If anyone has any idea why this is happening, I'd be happy to know.
This is the class code, if needed:
#pragma once
class Foo
{
public:
Foo();
Foo(int bok);
~Foo();
};
I am just trying to test default constructors, overloaded constructors, and destructors.
It should usualy print out the constructor as stated here:
Foo::Foo()
{
std::cout << "this is the default ctor" << std::endl;
}
Foo::~Foo()
{
std::cout << "this is the dtor" << std::endl;
// and this is the dtor output
}