Q201094: PRB: Error C2259 on "char" Type Redefinition in Visual C++
Article: Q201094
Product(s): Microsoft C Compiler
Version(s): 5.0,6.0
Operating System(s):
Keyword(s): kbCompiler kbSDKPlatform kbVC500 kbVC500bug kbVC600 kbVC600bug kbGrpDSTools kbNoUpdate
Last Modified: 02-MAY-2002
-------------------------------------------------------------------------------
The information in this article applies to:
- Microsoft Visual C++, 32-bit Enterprise Edition, versions 5.0, 6.0
- Microsoft Visual C++, 32-bit Professional Edition, versions 5.0, 6.0
- Microsoft Visual C++, 32-bit Learning Edition, version 6.0
-------------------------------------------------------------------------------
SYMPTOMS
========
Compiling a Visual C++ ActiveX Template Library (ATL) Project may result in the
Visual C++ compiler error C2259. This problem can occur when a parameter of type
char is not qualified as signed char or unsigned char.
RESOLUTION
==========
A workaround for this problem is to qualify "char" parameters as either
"unsigned char" or "signed char."
MORE INFORMATION
================
There is a discrepancy between the way an unqualified "char" parameter is
treated by the MIDL compiler and by the Add Method or Add Property dialog
boxes.
The MIDL compiler generates a Visual C++ prototype for the interface where the
parameter type is "unsigned char." MIDL's default type is unsigned unless
qualified with the "signed" keyword. The C++ method generated by the Add Method
to Interface or Add Property to Interface dialog boxes has a parameter type of
"char"; in the Visual C++ compiler, "char" is signed by default. This causes a
Visual C++ compiler error.
Steps to Reproduce Behavior
---------------------------
1. Create a new ATL COM AppWizard project in Visual C++, give the project a
name, and click OK. In this example, the project is called ErrTest.
2. Select the Server Type and then click Finish. A new skeleton project is
created. At the Information dialog box, click OK.
3. From the Insert menu, select New Class to create a new ATL class, give it a
name, and click OK. In this example, the class is named ErrTestClass.
4. From the ClassView tab of the Workspace, expand classes to expose the newly
created interface. In this example, it is IErrTestClass. Right-click the
interface and select Add Method to bring up the Add Method to Interface
dialog box.
5. In the Add Method to Interface dialog box, provide values for Method Name and
Parameters, and click OK. Here are the values for this example:
- Method Name: ErrTestMethod
- Parameters: char chErrTest
6. From the Build menu, select Rebuild All. In this example, three errors and
three warnings result. The problem discussed in this article is represented
by the following Visual C++ compiler error and warning messages:
error C2259: 'CComObject<class ErrTestClass>' : cannot instantiate
abstract class due to following members:
warning C4259: 'long __stdcall IErrTestClass::ErrTestMethod(unsigned char)' :
pure virtual function was not defined
7. Verify the workaround described above by repeating Steps 1-6, using "unsigned
char chName" as the Parameter in Step 5.
REFERENCES
==========
For more information, see the following article in the Microsoft Knowledge
Base:
Q193471 DOC: MIDL /char Switch Does Not Behave as Expected
Additional query words: kbDSupport kbdss
======================================================================
Keywords : kbCompiler kbSDKPlatform kbVC500 kbVC500bug kbVC600 kbVC600bug kbGrpDSTools kbNoUpdate
Technology : kbVCsearch kbAudDeveloper kbVC500 kbVC600 kbVC32bitSearch kbVC500Search
Version : :5.0,6.0
Issue type : kbprb
Solution Type : kbpending
=============================================================================
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.
Copyright Microsoft Corporation 1986-2002.