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

ID: Q201094


The information in this article applies to:


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:


  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 
Version           : winnt:5.0,6.0
Platform          : winnt 
Issue type        : kbprb 

Last Reviewed: July 15, 1999