BUG: C2321 Expanding Template with a Pointer to a Nested Class

Last reviewed: July 31, 1997
Article ID: Q150885
The information in this article applies to:
  • The Microsoft C/C++ Compiler (CL.EXE) included with: - Microsoft Visual C++, 32-bit Edition, versions 4.0, 4.1, 4.2, 5.0

SYMPTOMS

At the point where a class template is expanded using the new operator to a nested class, the compiler reports the following errors:

   [FileName](10) : error C2321: syntax error : unexpected 'A::B'

   [FileName](27) : fatal error C1004: unexpected end of file found

STATUS

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

WORKAROUND

There are two possible workarounds to this problem. Each is stated in terms of the sample code below:

  1. Remove t(new T()) from the initializer list and add t = new T(); to the body of the constructor. This workaround assumes class T is not a reference or a constant pointer.

  2. Change the definitions of class A and class B so that B is no longer nested in the definition of A.

Sample Code

   /* Compile options needed: None */
   template <class T> class C
   {
   public:
       C();
   private:
       T *t;
   };

   template <class T> C<T>::C() : t(new T())  // error
   {
   }

   class A
   {
   public:
       class B
       {
       };
   };

   main()
   {
       C<A::B> c;
       return 0;
   }
Keywords          : CLIss vcbuglist400 vcbuglist500
Version           : 4.0 4.1 4.2 5.0
Platform          : NT WINDOWS
Issue type        : kbbug


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


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