Quote Originally Posted by loves_oi View Post
i have tried the second one and fixed some deficient point in your code. It should be correct.
I'm sure you have the best intentions, but posting bad solutions without any form of explanation is not helpful.
Quote Originally Posted by PlutoRocks View Post
well.. you'll see, here is my problem:
Code:
class Knap
{
public:
	void fillArrays(Knap);
	int weight[99]; 
	int value[99]; 
	int W;
}
Please use code tags and properly indent your code to keep it readable.
Note that a class definition must be closed with a semicolon, you forgot that.

What's the reason for passing a Knap to the member function fillArrays? Since this is a normal member function, it already has access to an instance of Knap. In main you have to call the function on an instance of Knap, as in
Code:
myKnap.fillArrays(...);
The instance you called the member function on is available in the member function via the this pointer. The member variables of the Knap instance are even directly accessible. That is, you can write
Code:
void Knap::fillArrays()
{
    this->weight[0] = 1;
    // or just
    weight[0] = 1;
}
This will change the value of the member variable weight that belongs to the instance on which you called the fillArrays member function.

What happens in your code is that the Knap argument passed to the function is passed by value, which means that a copy is made and the function works on the copy. Since you only changed values in this copy, the values in your Knap instance in main are not affected.