1

Below code gives me:

In member function ‘void A::method()’:error: incomplete type ‘B’ used in nested name specifier B::meth();

I searched for solution to this error on SO found that I could use :: but didnt help

class B;
class A
{
    public:
    void method()
    {
        B::meth();
    }
};

class B
{
    public:
    void static meth()
    {
    }
};
Mohit Jain
  • 30,259
  • 8
  • 73
  • 100
lllook
  • 729
  • 2
  • 7
  • 20

2 Answers2

3

At the line A::method is defined, B is known only by name, not by its full definition.

You have to make sure that the full definition of B is known before you can use B::meth().

Option 1

Move the definition of B before the definition of A.

class B
{
    public:
    void static meth()
    {
    }
};

class A
{
    public:
    void method()
    {
        B::meth();
    }
};

Option 2

Move the definition of A::method after the definition of B.

class A
{
    public:
    void method();
};

class B
{
    public:
    void static meth()
    {
    }
};

void A::method()
{
   B::meth();
}
R Sahu
  • 204,454
  • 14
  • 159
  • 270
0

The issue is that class A is trying to access a member of class B before class B is defined. You should define class B first. Furthermore, consider renaming the classes so that they will be in alphabetical order.

Cole Dapprich
  • 33
  • 1
  • 7