using a function of a class which I'm in.

Hi guys.

I don't know if I framed the question correctly. I'll try to explain it by code. Let's say I have two classes a and b in the following way:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class a{
   int rr;
  public:
   a();
   ~a();
}

class b{
   a aa;
  public:
   b();
   ~b();
   void doDomthing();
}


Is there a way to run the "doSomthing()" function of b from a function within aa?

I hope I'm clear.

Yotam
I'm not sure I understand, do you mean something like this?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class a{
   int rr;
  public:
   a();
   ~a();
   void foo();
};

class b{
   a aa;
  public:
   b();
   ~b();
   void doSomething();
};

void A::foo ()
{
   b bb;
   bb.doSomething();
}
yes.

The idea is that I'll have a class box, and another class, lipid. each box contains lipid and the lipids might change their location from box to box.

You need to have access to an object of type class B in order to call one of B's member functions on it. So as long as the functions in class A have access to a B object you can do it. This might be member variables of class A like this:

1
2
3
4
5
6
7
8
9
class A
{
    B b; // member of type class B
public:
    void func()
    {
        b.doSomething(); // run the function on b
    }
};
Is there a way to pass a specific member in a class to a subclass? That is, I want a to use a function of b (and not B).
Topic archived. No new replies allowed.