access one classes function from another class

I just restarted programming (I had given up for a while), and have ran into a problem. How do you access the function that is in one class from another:
1
2
3
4
5
6
7
8
9
class a
{
public:
void afunc();
};
class b
{
void bfunc (a::afunc);//is that how you do this?
};

So that's what I want to do, but it doesn't work. Any help?
Last edited on
In order to call function afunc();, you need an object of type a.

So that's what I want to do
I'm not sure what it is that you want to do.
I want to be able to have bfunc use afunc. I was just asking how to do that. So I would have to do this?
1
2
3
4
5
6
7
8
9
10
class A
{
public:
void Afunc();
};
class B
{
A a;
void Bfunc (a.A::afunc);
};

So like that?
I want to be able to have bfunc use afunc.

Can you expand on or explain the word "use" here.

Currently it seems that you'd like to pass the address of the function as an input parameter to a function of class b. But somehow I don't think that's what you want or need.
By use I just mean be able to do something like this:
1
2
3
4
Bfunc
{
cout<<Afunc;
}

I keep on trying to do this but it gives me errors.
Maybe like this,
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class A
{
public:
    int Afunc() { return 5; };
};

class B
{
    A a;
public:
    void Bfunc ()
    {
        cout << a.Afunc();
    };
};
Last edited on
Oh thanks...I feal realy dumb
Topic archived. No new replies allowed.