FIX: C2065: Undeclared Identifier Creating a STL Function Object

Article translations Article translations
Article ID: 177431 - View products that this article applies to.
This article was previously published under Q177431
This article has been archived. It is offered "as is" and will no longer be updated.
Expand all | Collapse all

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

Use one of the following methods to work around this problem:

  • Use the "using namespace" directive instead of qualifying the function objects.
  • Pre-declare an instance of std::multiplies<int> to solve the problem.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft product listed at the beginning of this article. This problem was corrected in Visual C++ version 6.0 for Windows.

MORE INFORMATION

The following sample demonstrates the problem and the first workaround:
   /*
   * 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:
   /*
   * 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 ;
   }
				

Properties

Article ID: 177431 - Last Review: October 7, 2013 - Revision: 2.0
APPLIES TO
  • Microsoft Visual C++ 5.0 Enterprise Edition
  • Microsoft Visual C++ 5.0 Professional Edition
Keywords: 
kbnosurvey kbarchive kbbug kbfix kbvc600fix KB177431

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com