Question: Very new to c++ having trouble calling a function from another class.

Class B inherits from Class A, and I want class A to be able to call a function created in class B.

```
using namespace std;

class B;

class A 
{

public:

    void CallFunction ()
    {
        B b;
        b.bFunction();
    }

};

class B: public A
{
public:
    virtual void bFunction()
        {
            //stuff done here
        }

};

```

It all looks fine on screen (no obvious errors) but when I try to compile it i get an error C2079 'b' uses undefined class B.

I've tried making them pointers/ `friends` but I'm getting the same error.

Answer: 
```
    void CallFunction ()
    {   // <----- At this point the compiler knows
        //        nothing about the members of B.
        B b;
        b.bFunction();
    }

```

This happens for the same reason that functions in C cannot call each other without at least one of them being declared as a function prototype.

To fix this issue we need to make sure both classes are declared before they are used. We separate the declaration from the definition. [This MSDN article](https://msdn.microsoft.com/en-us/library/0e5kx78b.aspx) explains in more detail about the declarations and definitions.

```
class A
{
public:
    void CallFunction ();
};

class B: public A
{
public:
    virtual void bFunction()
    { ... }
};

void A::CallFunction ()
{
    B b;
    b.bFunction();
}

```
in A you have used a definition of B which is not given until then , that's why the compiler is giving error .