Re: What's with "typedef interface ID3DXLine ID3DXLine;" in d3dx9core.h?
- From: "Robert Dunlop [MS MVP]" <rdunlop@xxxxxxxx>
- Date: Tue, 4 Jul 2006 10:45:38 -0700
<res7cxbi@xxxxxxxxxxx> wrote in message news:1151641813.536950.179820@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
What is the purpose of "typedef interface ID3DXLine ID3DXLine;" in
d3dx9core.h?
im just curious, why does this header file have this piece of code at
line 681? isn't just defining itself again? all the other interfaces in
the header have something like this
thanks in advance
This is really more of a c++ question than DirectX specific, but I'll take a stab at it.
The typedef serves as a forward declaration, that is, it specifies the existence of such an interface before it is actually defined. This allows the line that follows it, which defines a type LPD3DXLINE as a pointer to that interface, even though the interface class has not been defined yet. Another example of a forward declaration without a typedef, that might be more apparent goes something like this:
class B;
class A {
...
B * m_pB;
}
class B {
...
A * m_pA;
}
Without the forward declaration "class B;" there would be a kind of "which came first, the chicken or the egg" problem, because the compiler would not know of the existance of the B class when it attempts to compile the A class and encounters a pointer to a type "B". If class B didn't have a pointer to an A instance you could just place the declaration of class B prior to that of class A, but since it does the same problem would arise compiling the B class. The forward declaration lets the compiler know that a declaration of a class type B will be forthcoming, establishing the type identifier before it is needed in the declaration of class A.
In the case of LPD3DXLINE, that typedef could be made after ID3DXLine has been defined. However, this would mean that you could not make use of that pointer type within the class declaration. While they don't make use of it in this case, the forward declaration would allow the LPD3DXLINE type to be used in the declaration of ID3DXLine, such as in the declaration of a member variable, or as a parameter or return value for a member function. So while none of the classes in d3dx9core.h make use of these pointer types within declaration of the same class, it is likely implemented for the sake of consistency.
--
Robert Dunlop
The X-Zone
http://www.directxzone.com/
Microsoft DirectX MVP
-------------
The opinions expressed in this message are my own personal views and do not reflect the official views of the Microsoft Corporation.
The MVP program does not constitute employment or contractual obligation with Microsoft.
.
- Prev by Date: Re: display object on screen that BitBlt can't copy
- Next by Date: Re: Calling GetContainer on IDirect3DSurface to get the parent swa
- Previous by thread: Open source libraries?
- Next by thread: Re: Render part of a mesh but not using subsets
- Index(es):
Relevant Pages
|