Microsoft KB Archive/201094

= PRB: Error C2259 on "char" Type Redefinition in Visual C++ ATL Project =

Article ID: 201094

Article Last Modified on 12/2/2003

-

APPLIES TO


 * Microsoft Visual C++ 5.0 Enterprise Edition
 * Microsoft Visual C++ 6.0 Enterprise Edition
 * Microsoft Visual C++ 5.0 Professional Edition
 * Microsoft Visual C++ 6.0 Professional Edition
 * Microsoft Visual C++ 6.0 Standard Edition

-



This article was previously published under Q201094



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
 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. Select the Server Type and then click Finish. A new skeleton project is created. At the Information dialog box, click OK. 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. 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. 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</li> Parameters: char chErrTest</li></ul> </li> 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

</li> Verify the workaround described above by repeating Steps 1-6, using "unsigned char chName" as the Parameter in Step 5.</li></ol>

<div class="references_section">