shadedecho
Programmer
bitmap.h:
bitmap.cpp:
test-bitmap.cpp:
The output of the above code is intended to be:
However, what I get is this:
I am sure this is something simple and stupid I am missing. Why are the destructors being called twice BEFORE the cout and then twice more after it?
Code:
#ifndef MYBITMAP
#define MYBITMAP
class bitmap {
public:
bitmap(void);
bitmap(int,int);
~bitmap(void);
static const int _default_width = 500;
static const int _default_height = 500;
private:
int _current_width;
int _current_height;
};
#endif
bitmap.cpp:
Code:
#include "bitmap.h"
#include <stdio.h>
#include <iostream.h>
using namespace std;
bitmap::bitmap(void) {
bitmap(_default_width,_default_height);
}
bitmap::bitmap(int setWidth, int setHeight) {
_current_width = setWidth;
_current_height = setHeight;
}
bitmap::~bitmap(void) {
cout << "destructor called." << endl;
}
test-bitmap.cpp:
Code:
#include "bitmap.h"
#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>
using namespace std;
int main() {
bitmap myBitmap;
bitmap* myBitmap2 = new bitmap();
cout << "should be before destructors." << endl;
delete myBitmap2;
return 0;
}
The output of the above code is intended to be:
Code:
should be before destructors.
destructor called.
destructor called.
However, what I get is this:
Code:
destructor called.
destructor called.
should be before destructors.
destructor called.
destructor called.
I am sure this is something simple and stupid I am missing. Why are the destructors being called twice BEFORE the cout and then twice more after it?