FIX: C2371: Cast to Struct Ptr in Default Arg of Class Member

Article translations Article translations
Article ID: 148504 - View products that this article applies to.
This article was previously published under Q148504
Expand all | Collapse all

SYMPTOMS

When encountering a cast to a structure pointer in the default argument of a class member function, the Visual C++ compiler generates the following error:
error C2371: 'MyClass' : redefinition; different basic types
This error does not occur if the function declaration is not a member of a class.

RESOLUTION

If you are casting from an integral literal, remove the cast. For example, change this:
   MyFunc (struct MyStruct *p = (struct MyStruct*)0);  //C2371 error
				
to this:
   MyFunc (struct MyStruct *p = 0);                    //no error
				
If you are casting from a different structure type, remove the struct keyword from the cast. For example, change this:
   yFunc (struct MyStruct *p = (struct MyStruct*)x);  //C2371 error
				
to this:
   MyFunc (struct MyStruct *p = (MyStruct*)x);         //no error
				

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.

Properties

Article ID: 148504 - Last Review: July 5, 2005 - Revision: 1.1
APPLIES TO
  • Microsoft Visual C++ 4.0 Professional Edition
  • Microsoft Visual C++ 4.1 Subscription
  • Microsoft Visual C++ 4.2 Professional Edition
  • Microsoft Visual C++ 4.2 Enterprise Edition
  • Microsoft Visual C++ 5.0 Learning Edition
  • Microsoft Visual C++ 5.0 Learning Edition
Keywords: 
kbbug kbcompiler kbcpponly kbfix kbvc500fix KB148504
Retired 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.

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com