Im wondering if someone could clarify a problem im having.
Basically im trying to figure out how i can go about having a Class A object as an attribute of Class B,while still using Class A's functions.

For example if have a class called clockRadio.In turn i have another class called alarm,

Alarm has the functions
- set time.
- view time

Is it possible for me to create an object of clockRadio and use class Alarms functions through this object.

Im sorry if this does not make any sense but im very confused on this and any help would be greatly appreciated.

Yes you can do that, for example

class A
            int func() { return 1;};

class B
          A a;

int main()
         B b;

So would i be correct in saying that to do this i will need to declare the class i wish to associate as a public attribute?

For example

class Radio {

             Alarm a

class Alarm {

           set/view time


Is this known as association?

Edited 3 Years Ago by Nick Evan: Fixed formatting

Not necessarily. You can have the other class as a private or protected member too or a pointer, or reference, depending on how you are going to use it.

I think it is composition, which if I'm not wrong is a type of association, but you should cross check that.

Thanks for the help,im not so confused anymore.And for future reference it is indeed composition.

This question has already been answered. Start a new discussion instead.