BUG: C2065: Undeclared Identifier Creating a STL Function Object

Last reviewed: December 1, 1997
Article ID: Q177431
The information in this article applies to:
  • Microsoft Visual C++, 32-bit Edition, version 5.0

SYMPTOMS

Creating the STL function object “binder2nd” causes the compiler to generate the following error C2065:

   'identifier' : undeclared identifier

It is the “std::multiples<int>(): line that causes the namespace to be lost.

RESOLUTION

One of the following methods can be used to work around this problem:

  • Use the 'using namespace' directive instead of qualifying the function objects.

    -or-

  • Pre-declaring an instance of std::multiplies<int> solves the problem.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft product listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

The following sample demonstrates the problem and the first workaround.

Sample Code

   /*
   * Compiler Options: /GX
   */

   #include <algorithm>
   #include <functional>
   #include <iostream>

   #define BUG
   //Workaround: Comment the line above.
   //Uncomment the line below.
   //#define WORKAROUND

   #ifdef WORKAROUND
   using namespace std ;
   #endif

   int main()
   {

   #ifdef BUG
      std::binder2nd< std::multiplies<int> >
                     times_two(std::multiplies<int>(), 2);
   #endif

   #ifdef WORKAROUND
       binder2nd< multiplies<int> > times_two(multiplies<int>(), 2);
   #endif

      int n = times_two(4) ;
      std::cout << "n = " << n << std::endl ;
      return 0 ;
   }

The following sample demonstrates the problem and the second workaround.

Sample Code

   /*
   * Compiler Options: /GX
   */

   #include <algorithm>
   #include <functional>
   #include <iostream>

   #define BUG
   //Workaround: Comment the line above.
   //Uncomment the line below.
   //#define WORKAROUND

   int main()
   {

   #ifdef BUG
      std::binder2nd< std::multiplies<int> >
                     times_two(std::multiplies<int>(), 2);
   #endif

   #ifdef WORKAROUND
      std::multiplies<int> mi ;
      std::binder2nd< std::multiplies<int> > times_two(mi, 2);
   #endif

      int n = times_two(4) ;
      std::cout << "n = " << n << std::endl ;
      return 0 ;
   }

REFERENCES

Please see the following help topics in the Microsoft Visual C++ online documentation for more information on ”binder2nd”:

   TITLE: binder2nd
   URL:   mk:@ivt:vclang/STDLIBBLD/FUNCTIO2_BINDER2ND.HTM

   TITLE: Visual C++ 4.2 Standard Template Library Tutorial
   URL:   mk:@ivt:tatech/F1/DB/S4249.HTM#sec58

Keywords          : CPPIss CPPLngIss STLIss vcbuglist500 kbbuglist
Version           : WINNT:5.0
Platform          : winnt
Issue type        : kbbug
Solution Type     : kbfix


================================================================================


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: December 1, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.