- Joined
- Jan 17, 2004
I have an array of class objects. I setup default destructor for the class that has output inside its code block.
Problem:
When array of objects goes out of scope they obviously invoke the destructors which outputs the code written in its block. Problem is I only need one output and then the rest can be destroyed properly.
so you can see there is an issue about having the output in the destructor. But it is a requirement to have.
How do I avoid it ???
I was thinking right before program exit I could I could delete one object (which would only display one destructor output) then jump to a system exit (avoiding output of other destructors) ...
That doesn't sit right with me though .. Any ideas ??
Problem:
When array of objects goes out of scope they obviously invoke the destructors which outputs the code written in its block. Problem is I only need one output and then the rest can be destroyed properly.
Code:
#include <string>
using namespace std;
class MyAccount
{
public:
void SetAccount();
void GetAccount();
MyAccount();
~MyAccount();
private:
string FirstName;
string LastName;
};
Code:
#include "MyAccount.h"
#include <iostream>
using namespace std;
void MyAccount :: SetAccount(){};
void MyAccount :: GetAccount(){};
MyAccount :: MyAccount(){};
MyAccount :: ~MyAccount()
{
cout << endl << endl << " Programmed By - " << endl << endl;
};
Code:
#include <iostream>
#include <stdio.h>
#include <ctype.h>
#include <conio.h>
#include "MyAccount.h"
using namespace std;
int main()
{
MyAccount Accounts[100];
return 0;
}
Code:
[U][B]!!!!!!!!!!!!!!!!!! BAD OUTPUT !!!!!!!!!!!!!!!!!!!!![/B][/U]
Programmed By -
Programmed By -
Programmed By -
Programmed By -
Programmed By -
Programmed By -
Programmed By -
Programmed By -
Programmed By -
Programmed By -
Programmed By -
Programmed By -
Programmed By -
Programmed By -
ETC ..................................... 100 times ...................
Press any key to continue .......
Code:
[U][B] !!!! GOOD OUTPUT !!!![/B][/U]
Programmed By -
Press any key to continue .......
How do I avoid it ???
I was thinking right before program exit I could I could delete one object (which would only display one destructor output) then jump to a system exit (avoiding output of other destructors) ...
That doesn't sit right with me though .. Any ideas ??