The arguments passes to the train constructor are usually used in the initialization of some member values however you haven't got an members to initialize. For example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
class train {
// private by defualt
int x;
int y;
int Direction;
// etc...
public:
train(int X,int Y,int direction, int length, int displacement, int passengerlimit) {
x = X;
y = Y;
Direction = direction;
}
int move(void);
void reverse(void);
} train1;
EDIT* I should note however that the method used in the example above is not the best way to utilize the contrsuctor. Refer to this article for better use: http://www.cplusplus.com/forum/articles/17820/
class train {
public:
train(int X,int Y,int direction, int length, int displacement, int passengerlimit);
int move(void);
void reverse(void);
void append(passenger value);
passenger take(void);
int length(void);
void color(GColour color);
BufferGeneric <passenger> *passengers;
private:
int train_index;
int ypos;
int disp;
int len;
int front;
int back;
GColour tcolor;
int disparg;
int lenarg;
void drawTrainSet ( );
};
And this is part of the constructor:
1 2 3 4 5 6 7 8 9 10 11
train::train(int X,int Y,int direction, int length, int displacement,int passengerlimit)
{
ypos = Y;
front = length; //X;
disparg = displacement;
lenarg = length;
tcolor = GwinColourNames::BLACK; // default train colour
And we have train train1(0,1,1,60,4,MaxPassengers);
With the value 4 (which is displacement) I need to change (later on in the code)
How do you expect to access the public member disparg when it happens to be private? That's an interesting contradiction you have there.
int displacement is a constructor argument. It's not a member of your class. The member against which it is assigned, disparg, is a private member and cannot be accessed outside the class.