Article ID: 150885 - Last Review: July 5, 2005 - Revision: 1.1

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

This article was previously published under Q150885

On This Page

Expand all | Collapse all

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

This bug was corrected in Microsoft Visual C++, version 6.0.

RESOLUTION

There are two possible workarounds to this problem. Each is stated in terms of the sample code below:
  • 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.
  • 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
{
}

lass A
{
public:

   class B
   {
   };

};

main()
{

   C<A::B> c;
   return 0;

}
				

APPLIES TO
  • Microsoft Visual C++ 4.0 Standard Edition
  • Microsoft Visual C++ 4.1 Subscription
  • Microsoft Visual C++ 4.2 Enterprise Edition
  • Microsoft Visual C++ 4.2 Professional Edition
  • Microsoft Visual C++ 5.0 Enterprise Edition
  • Microsoft Visual C++ 5.0 Professional Edition
Keywords: 
kbbug kbfix kbvc600fix KB150885
Retired KB ArticleRetired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
 

Article Translations