getters and setters

For a project i need getters and setters. The problem is that only when i inizialize my value and set it, the value is correct and updated. But futher use doesn't do anything. The value gets updated with the setter below, but.
1
2
3
void train::setCurrentStation(string newCurrentStation){
	train::currentStation = *(&newCurrentStation);
}


Here in my getter, the value stays the same. Also strange is that the adress of currentStation is different in both functions.
1
2
3
string train::getCurrentStation(){
	return train::currentStation;
}


Can you help me
But futher use doesn't do anything.

You'll need to elaborate on that a bit.

Inside of the functions, you don't need to prefix the variables with train::. Also, why are you dereferencing the value at the address of the parameter you pass in, rather than just assigning the value?

currentStation = newCurrentStation;
That would suffice.
Last edited on
Topic archived. No new replies allowed.