FIX: C2989 Declaring Template Class in a Namespace
Article ID: 163995
Article Last Modified on 7/5/2005
APPLIES TO
- Microsoft Visual C++ 4.2 Enterprise Edition
- Microsoft Visual C++ 4.2 Professional Edition
This article was previously published under Q163995
SYMPTOMS
A template class is defined inside a namespace that has the same name as a
non-template class declared at global scope. When you compile this
construct, the following error message appears:
error C2989: '<classname>' : template class has already been defined as
a non-template class
RESOLUTION
There are 3 ways to work around this problem.
- Change the name of one of the classes involved. If this is possible, it
may be the best solution because having two different classes with the
same name could lead to confusion.
- Move the definition of the non-template class so that it appears after
the definition of the template class. See sample code below.
- Move the definition of the non-template class into a namespace (other
than the one the template class is defined in).
STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed
at the beginning of this article. This bug was corrected in Visual C++
version 5.0.
Additional query words: C2989 template namespace
Keywords: kbbug kbfix kblangcpp kbvc500fix kbcpponly kbcompiler KB163995