473,800 Members | 2,689 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

~destructor trouble

TMS
119 New Member
I'm a little rusty with C++ so bear with me.

My assignment has me amending a database file by adding 'tombstones' to records that are to be omitted later by the destructor. The database brings in a file (lets call it A) then there is a menu of operations. If the user wants to remove a file, they use the remove option which places a 'b' (in this case) in front of the Social Security Number.

That is all fine and good. My amendments take care of that. NOW, I'm having problems writing the new database that excludes the tombstoned records. I can get it to print to the screen, but I can't get it to print out. I know I need to define an fstream object, and use it in a function called writeToFile(). But it doesn't work.

database is declared as a type fstream

Here is my destructor:

//function to omit tombstoned items, write data to file
template<class T>
Database<T>::~D atabase()
{
T tmp; //variable to access student file
fstream newDatabase; //my attempt at declaring the new database object

database.open(f Name,ios::in|io s::binary); //this works fine
while (true )
{
tmp.readFromFil e(database);
if database.eof()) //finish when at the end of file
break;
if(!tmp.isNull( )) //check for tombstone
{
//newDatabase = database; //doesn't work
//tmp.writeToFile (newDatabase); //this causes
//infinite loop
cout << tmp << endl; // omits tombstoned items //prints to screen just fine
}
}

database.close( );
}

any suggestions?
Sep 12 '06 #1
1 1955
redaccord02
3 New Member
have you received any replies? It seems that there are some pieces missing within your destructor. Post the whole code and i'll check it out.
Dec 25 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

16
1866
by: Timothy Madden | last post by:
Hy I have destructors that do some functional work in the program flow. The problem is destructors should only be used for clean-up, because exceptions might rise at any time, and destructors will be called for clean-up only. So how can I tell, from within the destructor, if the call has been made as part of normal flow of control and the destructor can play its functional role, or if the call has been made as a result of an...
37
4182
by: WittyGuy | last post by:
Hi, I wonder the necessity of constructor and destructor in a Abstract Class? Is it really needed? ? Wg http://www.gotw.ca/resources/clcm.htm for info about ]
4
3884
by: iTooo | last post by:
What a subject, mhhh not resumable. Here is my problem: I'm using a template class for lists, upon deletion it deletes its elements, ok, works fine. Trouble comes when I put in this list inherited classes and the list is templated for the parent class. When the list deletes its elements, the destructor called is not the one of the classes, but their parent's. Here is a little example code
11
5313
by: Ken Durden | last post by:
I am in search of a comprehensive methodology of using these two object cleanup approaches to get rid of a number of bugs, unpleasantries, and cleanup-ordering issues we currently have in our 4-month old C#/MC++ .NET project project. I'd like to thank in advance anyone who takes the time to read and/or respond to this message. At a couple points, it may seem like a rant against C# / .NET, but we are pretty firmly stuck with this approach...
8
1815
by: JAL | last post by:
According to MSDN2, if a managed class throws an exception in the constructor, the destructor will be called. If an exception is thrown in the constructor the object never existed so how in the world can the destructor of a object that does not exist get called! Here is the MSDN2 document: Code authored in Visual C++ and compiled with /clr will run a type's destructor for the following reasons: ....
10
459
by: piboye | last post by:
Hi ! I'm a academician in china. I have been intereted in C++ lasting. In reading the C++ Primer book, i have a trouble about union. In the book ,it said that union can have constructors and destructor ,or other member functions. I can understand using constructors and memeber functions,but what is destructor used for? I have appealled to the forums in chinese ,but no enough usefull feedback.
3
1256
by: Noah Roberts | last post by:
I am trying to pull behavior out of a class so that the class can be replaced. Part of that behavior takes place in the destructor of the object. I need call sites to change so that they call a cleaner function and then let the object get deleted normally. Any good ideas on a nice approach? Best I can seem to come up with is to privatize the destructor and let the compiler complain. Problem is that it goes a little insain and I think...
3
1828
schmals
by: schmals | last post by:
I am building a bigint class and currently having an issue with overloading operators simple +, -, and * operators with my destructor. The bigint class contains a dynamically allocated array of int's. When my destructor is called, the dynamically allocated memory gets dissolved. When overloading +, -, and *, I create a new bigint called answer which, obviously, holds the answer to the operations. My problem is that I return answer from the...
3
1911
by: GAURAV AGRAWAL | last post by:
Hi Guys, Can someone please explain me why this is happening #include<iostream> using namespace std; class a { public: int a1; // If I remove this it'll work fine
9
2060
by: itdevries | last post by:
Hi, I've ran into some trouble with an overloaded + operator, maybe someone can give me some hints what to look out for. I've got my own custom vector class, as a part of that I've overloaded the + operator by means of a friend function. Everything worked fine until I decided to use a variable array size (by using new/delete), now I get an error when a temporary object is deleted (e.g. after addition), the error occurs at the delete...
0
9690
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10504
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10274
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10251
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10033
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7576
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5469
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.