Class declaration and its name

Hello!

I read on MSDN that:

A class name whose declaration has not yet been encountered by the compiler can be used in an extern declaration. The name introduced with such a declaration cannot be used until the class declaration has been encountered.

Is this correct example ?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class A;
void fun(A ob);   //extern declaration

class A
{
    //...
};

void fun(A ob)
{
    //here we use ob and its data members
}

int main()
{
    A x;
    fun(x);
}
Yeah. That's also known as "forward declaring" and is a common technique, as it's the only way to really get around circular dependency issues.

Obligatory link: http://cplusplus.com/forum/articles/10627/#msg49679 (see section 4)
Topic archived. No new replies allowed.