How to Access a Private Variable?

Posted by SoulBeaver on Stack Overflow See other posts from Stack Overflow or by SoulBeaver
Published on 2010-06-10T20:23:52Z Indexed on 2010/06/10 21:33 UTC
Read the original article Hit count: 306

Filed under:
|
|
|

This question isn't meant to sound as blatantly insulting as it probably is right now.

This is a homework assignment, and the spec sheet is scarce and poorly designed to say the least. We have a function:

double refuel( int liter, GasStation *gs )
{
    // TODO: Access private variable MaxFuel of gs and decrement.
}

Sound simple enough? It should be, but the class GasStation comes with no function that accesses the private variable MaxFuel. So how can I access it anyway using the function refuel?

I'm not considering creating a function setFuel( int liter ) because the teacher always complains rather energetically if I change his specification. So... I guess I have to do some sort of hack around it, but I'm not sure how to go about this without explicitely changing the only function in GasStation and giving it a parameter so that I can call it here.

Any hints perhaps?

© Stack Overflow or respective owner

Related posts about c++

Related posts about homework