|
-
April 4th, 2011, 09:33 PM
#1
How to make a function change a variable
I can't get my functions to change the value of my variables! 
I know usually you could put in a "&" to let the function change the value, like:
void exampleFunction(int& number)
well.. you'll see, here is my problem:
//***********************************************************************
class Knap
{
public:
void fillArrays(Knap);
int weight[99];
int value[99];
int W;
}
int main
{
Knap myKnap;
myKnap.fillArrays(myKnap);
//---------------------THE PROBLEM:------------------
//after the last statement, though, all variables (myKnap.value[i], etc.) are still zero! 
}
void Knap::fillArrays(Knap myKnap)
{
//this function puts things in myKnap.value[i], myKnap.weight[i] and myKnap.W
//in this function, however, when I do a
cout<<myKnap.value[i],
// the values are correct. So the information is getting lost somewhere...
}
//***********************************************************************
I've tried:
in class: void fillArrays(Knap);
in main: myKnap.fillArrays(myKnap);
in funct: void Knap::fillArrays(Knap myKnap){
in class: void fillArrays(Knap&);
in main: myKnap.fillArrays(myKnap);
in funct: void Knap::fillArrays(Knap& myKnap){
in class: void fillArrays(Knap*);
in main: myKnap.fillArrays(myKnap);
in funct: void Knap::fillArrays(Knap* myKnap){
but none of these have worked yet...
I'm sure this is a really silly question but thanks for helping me out!!!!!!!! ^_^
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|