473,404 Members | 2,195 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

operator overloading/destructor problem

schmals
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 operator overloading functions, and at that point my destructor is automatically called and deletes the array I was trying to pass back as a part of the answer. This is causing me all sorts of trouble. Any ideas on how to fix it??

Thank You!!!!!
Oct 31 '07 #1
3 1809
arunmib
104 100+
I think you will know that "a destructor is called for a class object when that object passes out of scope" . You are certain this is not your case.....This is a simple thing, but many of us (rather me) tend to forget this often....
Oct 31 '07 #2
weaknessforcats
9,208 Expert Mod 8TB
My problem is that I return answer from the operator overloading functions, and at that point my destructor is automatically called and deletes the array I was trying to pass back as a part of the answer.
I'll bet you haven't written a copy constructor and are just passing back the address of the array rather than a copy of it.
Oct 31 '07 #3
ah, yes... you are completely right... i did miss that... thank you much!
Nov 1 '07 #4

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

Similar topics

6
by: - Steve - | last post by:
If you want to see all the code it's at http://planetevans.com/c However I think I have all the relevant parts here. main() makes the following call IntArray c = a + b; // IntArray is my...
20
by: Ioannis Vranos | last post by:
When we use the standard placement new operator provided in <new>, and not a definition of owr own, isn't a call to placement delete enough? Consider the code: #include <new>
11
by: Jonan | last post by:
Hello, For several reasons I want to replace the built-in memory management with some custom built. The mem management itlsef is not subject to my question - it's ok to the point that I have...
7
by: Eckhard Lehmann | last post by:
Hi, I try to recall some C++ currently. Therefore I read the "Standard C++ Bible" by C. Walnum, A. Stevens and - of course there are chapters about operator overloading. Now I have a class...
3
by: md | last post by:
Hi, the following code is working for static objects. ie the statement IntArray x(20); my problem is i want to use this overloading operator for dynamically created objects...
16
by: EM.Bateman | last post by:
Working on Visual Studio .Net I've implemented a class: #ifndef CONTRIBUTOR_H #define CONTRIBUTOR_H enum Gender {male=1, female, unk}; #include <iostream> #include <iomanip> #include...
4
by: hjast | last post by:
I'm trying to implement a = operater to set one circle or rectangle to another and this is giving me all kind of bugs. #include <iostream.h> class Shape { private: int x_Center,...
4
by: fabian.lim | last post by:
Hi All, Im a newbie to C++, I am trying to customize the vector template STL to a template Class. My code is shown below. Im confused about something and maybe somebody here might be able to...
1
by: fabian.lim | last post by:
Hi all, Im having a problem with my code. Im programming a vector class, and am trying to overload the () operator in 2 different situations. The first situation is to assign values, e.g. Y =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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,...
0
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...
0
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...
0
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...

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.