FIX: C2371: Cast to Struct Ptr in Default Arg of Class Member
This article was previously published under Q148504
This article has been archived. It is offered "as is" and will no longer be updated.
When encountering a cast to a structure pointer in the default argumentof a class member function, the Visual C++ compiler generates thefollowing error:
error C2371: 'MyClass' : redefinition; different basic types
This error does not occur if the function declaration is not a member ofa class.
If you are casting from an integral literal, remove the cast. For example,change this:
MyFunc (struct MyStruct *p = (struct MyStruct*)0); //C2371 error
MyFunc (struct MyStruct *p = 0); //no error
If you are casting from a different structure type, remove the structkeyword from the cast. For example, change this:
yFunc (struct MyStruct *p = (struct MyStruct*)x); //C2371 error
MyFunc (struct MyStruct *p = (MyStruct*)x); //no error
Microsoft has confirmed this to be a bug in the Microsoft products listedat the beginning of this article. This bug was corrected in Visual C++version 5.0.
Article ID: 148504 - Last Review: 01/07/2015 06:18:23 - Revision: 1.1
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: kbnosurvey kbarchive kbbug kbcompiler kbcpponly kbfix kbvc500fix KB148504