In a .h if I have:
#pragma once
#include <xxxx.h>
#include "yyyy.h"
class AAAAAA;
class BBBBBB;
class ZZZZZZ
{
public:
// etc
};
using class AAAAAA; is forward declaring a class right?
Why would one do this?
Is it needed?
What are the benefits? Drawbacks?
Why would one do this?
Because the compiler only knows names that have been declared. So if you want to use a class, you have to declare it. But if its definition depends on its user, a forward declaration can suffice if the user doesn't depend on the definitin of the class in turn, but just on its declaration (= name).
In particular, if the user just needs a pointer or referece, it doesn't depend on the definition. But in the cases listed (which do not claim to be exclusive, since it's a standard non-normative excerpt), the user depends on the definition of class T if
In these cases, a forward declaration will not suffice and you need to fully define it.
Is it needed?
Yes, in the cases where it is needed it is needed. In the following case it is, because both classes refer to each other.
class A;
class B {
// forward declaration needed
void f(A);
};
class A {
void f(B);
};
// "- a function with a return type or argument type of type T is defined"
void B::f(A) {
}
The member function definition required not only a declaration but also the definition of class A.
What are the benefits? Drawbacks?
The benefits are that your program compiles. The drawback is that you have polluted the scope with just another name. But that's the necessary evil of it.