Original Post
Hi. I just spent one hour hunting a very stupid bug in my code. The problem was that a template parameter and a structure in my code had the same name. The compiler didn't say anything but it was making a confusion. I can change the name but it's not very elegant, the more i had new structures in my code, the more i risk to face the problem again. Here what was the problematic code : I have a class wrapper class that encapsulates D3D, one of the methods in it is : template <typename VERTEX> bool DrawTriangles (const VERTEX * const verts, const unsigned int num_verts) { if (d3d9_device) { d3d9_device->BeginScene (); d3d9_device->SetFVF (VERTEX::VERTEX_FORMAT); d3d9_device->DrawPrimitiveUP (D3DPT_TRIANGLELIST, num_verts / 3, verts, sizeof (VERTEX)); d3d9_device->EndScene (); } return true; } And somewhere else, i have a structure named VERTEX. I also have a structure named QUAD_VERTEX i use for rendering transformed vertices. Now, when i was sending vertices of the type QUAD_VERTEX to the DrawTriangles method, instead of substituting the template parameter named VERTEX to the QUAD_VERTEX type, and then use QUAD_VERTEX::VERTEX_FORMAT to set the FVF, it was using VERTEX::VERTEX_FORMAT. Of course VERTEX::VERTEX_FORMAT exists because of the VERTEX structure, but it's not at all what i wanted to code. When i wrote d3d9_device->SetFVF (VERTEX::VERTEX_FORMAT); i wanted VERTEX to refer to the template parameter. I find it very strange that the preference is not given to the template parameter, and at least my compiler should warn me about a possible conflict. Is this a bug in the compiler ? Is there something i can do in my code to prevent this to happen again ? I hope someone can help me here. I would really apreciate it. Thanks in advance.