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_specifierbe so that I can invoke AC's methods
from a Car as outlined in the code above?
Thanks. 4 1550
"gccntn" <gc****@yahoo.comwrote in message
news:11*********************@v3g2000hsg.googlegrou ps.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_specifierbe so that I can invoke AC's methods
from a Car as outlined in the code above?
public.
On 2 Nov, 03:48, "Jim Langston" <tazmas...@rocketmail.comwrote:
"gccntn" <gcc...@yahoo.comwrote in message
news:11*********************@v3g2000hsg.googlegrou ps.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_specifierbe 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.
On 2007-11-02 20:55, gccntn wrote:
On 2 Nov, 03:48, "Jim Langston" <tazmas...@rocketmail.comwrote:
>"gccntn" <gcc...@yahoo.comwrote in message
news:11*********************@v3g2000hsg.googlegro ups.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_specifierbe 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.
Make it a private member (or use private inheritance) and provide access
methods for the things you want to allow.
--
Erik Wikström
"gccntn" <gc****@yahoo.comwrote in message
news:11**********************@19g2000hsx.googlegro ups.com...
On 2 Nov, 03:48, "Jim Langston" <tazmas...@rocketmail.comwrote:
>"gccntn" <gcc...@yahoo.comwrote in message
news:11*********************@v3g2000hsg.googlegro ups.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_specifierbe 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.
Encapsulation.
class Car
{
public:
void SwitchOnAC() { acUnit.switchon(); }
private:
AC acUnit;
}; This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: James Stroud |
last post by:
Hello All,
Because of my poorly designing a database, I have recently found it necessary
to explore the wonders of the Python pseudo-switch:
do_case = { "A" : lambda x: x,
"B" : lambda x: x,...
|
by: Medi Montaseri |
last post by:
Hi,
Given a collection of similar but not exact entities (or products)
Toyota, Ford, Buick, etc; I am contemplating using the Abstraction pattern
to provide a common interface to these products....
|
by: john smith |
last post by:
If I create an object and pass it by reference to two other functions, and
the other two function have separate threads
must I worry about threadsafety? The two functions could modify the myCar...
|
by: aliensite |
last post by:
Can I have an array of objects without numbering?
I have an array I frequently edit, and its a pain
to renumber the entire array if I insert an object
in between existing objects.
// define...
|
by: Graham McDonald via .NET 247 |
last post by:
I have an classic object model, base class with two or moresubclasses. When I know exactly that there is only these twoclasses then I have no problem serilaising and deserialsing theinstances....
|
by: portroe |
last post by:
Hi
I am using console.Writeline in my simple program. I do not however see
anything happening in the output window when I debug,
there are also no error messages,
Has anybody a tip on what...
|
by: Bernard Bourée |
last post by:
Is there a way to overpass the impossibility of VN.NET to accept the multi
heritage, that is to allow a class to inherit from TWO mother classes ?
--
Bernard Bourée
bernard@bouree.net
|
by: per9000 |
last post by:
Hi all,
I have a question I am unable solve.
I have an inheritance graph like this:
// CAR ----- MUSICAR ---- NICECAR
// \ \
// \ +------ OLDCAR
// \
// ...
|
by: Carmen Sei |
last post by:
to delcare an object with pointer -
MyCar * mycar = new MyCar;
mycar->Create();
========================
to delcare an object without pointer -
MyCar mycar = new MyCar;
mycar.Create();
...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |