FIX: Using String Constant as Default Argument Doesn't Work (124524)
The information in this article applies to:
- Microsoft Visual C++ 2.0, when used with:
This article was previously published under Q124524 SYMPTOMS
Using a string constant to initialize a character pointer as a default
parameter argument in a class member function does not work as expected.
Instead of assigning the address of the string constant to the pointer, the
compiler uses a different existing string constant.
CAUSE
This is a problem with character constants within a class definition, no
matter how they are used. The compiler always uses the last string constant
in the class definition.
RESOLUTION
To work around the problem, create a static character pointer that is set
to the desired string constant and use that static variable to initialize
the character pointer parameter of the constructor. Typically, string
constants are defined globally in a header file so that they can be easily
modified.
STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed
at the beginning of this article. This problem was corrected in Microsoft
Visual C++, 32-bit Edition, version 4.0.
Modification Type: | Minor | Last Reviewed: | 7/5/2005 |
---|
Keywords: | kbbug kbCompiler kbCPPonly kbfix KB124524 |
---|
|