PRB: C2129 Generated With Forward Reference Used in Prototype

Last reviewed: July 25, 1997
Article ID: Q114536

The information in this article applies to:
  • The Microsoft C/C++ Compiler (CL.EXE) included with: - Microsoft C/C++ for MS-DOS, version 7.0 - Microsoft Visual C++ for Windows, versions 1.0, 1.5 - Microsoft Visual C++ 32-bit Edition, versions 1.0, 2.0, 4.0

SYMPTOMS

Compiling a C++ source file which uses a forward reference to a struct in a function prototype will cause the compiler to generate the following error:

    error C2129: static function 'Function' declared but not defined

The sample code shown below can be used to illustrate this problem. Note: the error does not occur if the same file is compiled as a C source file.

CAUSE

This is by design. In C++, a tag not previously seen is entered in the current scope. In the sample code, the ForwardRef appearing in the parameter list is a different struct than the one defined afterwards.

RESOLUTION

To resolve this problem, move the declaration of the struct so that it is located before the function prototype.

Sample Code

   /* Compile options needed: /Tp to force this to be compiled as a C++
   *                          source file.
   */

   static void Function( int i, struct ForwardRef * frPtr );

   // To work around this problem place the following declaration before
   // the Function prototype.

   struct ForwardRef
   {
       int data;
   };

   void main( void )
   {
       struct ForwardRef *frPtr;
       int j;
       Function( j, frPtr );
   }

   static void Function( int i, struct ForwardRef *frPtr ){}


Additional query words: 8.00 8.00c 9.00
Keywords : CLIss
Version : 7.0 1.0 1.5 2.0 4.0
Issue type : kbprb
Solution Type : Info_Provided


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 25, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.