Solved All reasons a variable isn't what is expected in C++

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

des000

Thread Starter
Joined
May 29, 2008
Messages
307
What are all the reasons a variable isn't what is expected in C++? For example, I have a class, Function.
Function has an unsigned long int, itsdef. It is initialized to 0 in the constructor. It is assigned to the current object in the copy constructor.

There is a method, definition(), which is overloaded. definition(unsigned long int d), assigns d to itsdef. definition() returns itsdef.

When I call definition(unsigned long int d), and then immediately call definition(), definition() returns 0.

There is another level of this too. I have a class Function_Stack, which contains an Array<Function> itsstk. I have a method get_function(unsigned long I), which returns a Function, based off of the index. When fed with the index corresponding to the proper Function (I've checked, it's referring to the proper Function), as in get_function(index).definition(I + 3) to put it in, and get_function(index).definition() to return the value immediately after, I get some large number.

These are separate parts of the code, but they are related. What could be going wrong and what are all the reasons it could be going wrong?
 

des000

Thread Starter
Joined
May 29, 2008
Messages
307
The problem in this case, was that Function_Stack::get_function(), was declared to return Function. It was making too many copies! Instead, it needed to be Function &. Then everything worked fine.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top