On 2 Nov, 03:48, "Jim Langston" <tazmas...@rocketmail.com> wrote:
"gccntn" <gcc...@yahoo.com> wrote in message
news:1193981449.606045.68850@v3g2000hsg.googlegroups.com...
I know the subject of the post is a bit cryptic, but here is what I'd
like my code to look like:
int main()
{
Car myCar;
myCar.Start();
myCar.acUnit.SwitchOn(); // invoke TurnOn(), method of class
AC, which is a member of class Car
myCar.acUnit.SetTemp(75); // invoking SetTemp(), method of class
AC, which is a member of class Car
...etc...
myCar.Stop();
return 0;
}
How should I declare classes Car and AC?
The way I see things, this is what the declarations would look like:
class AC
{
public:
SwitchOn();
SwitchOff();
SetTemp();
GetTemp();
private:
...etc...
}
class Car
{
public:
Start();
Stop();
...etc...
<access_specifier>:
AC acUnit;
Engine engine;
...etc...
}
What should <access_specifier> be so that I can invoke AC's methods
from a Car as outlined in the code above?
public.- Nascondi testo tra virgolette -
- Mostra testo tra virgolette -
What if I wanted to grant Car's methods access to AC's methods, BUT I
did NOT want users of the Car class to have access to all the methods
in AC?
For instance, while I would a Car to initialize the AC:
bool Car::Start()
{
acUnit.Initialize(); // I WANT TO ALLOW THIS
...etc...
}
I would NOT want someone to initialize acUnit via the Car class:
int main()
{
Car myCar;
myCar.acUnit.Initialize(); // NO!!!
...etc...
}
Any suggestions? Thanks again for your help.
methods for the things you want to allow.