BUG: You may receive an error message C2664 from the compiler if you call the CStringT constructor and you pass a CFixedStringMgr pointer as an argument in Visual C++ .NET 2003 (328431)
The information in this article applies to:
- Microsoft Visual C++ .NET (2003)
This article was previously published under Q328431 SYMPTOMS If you call the CStringT constructor and you pass a
CFixedStringMgr pointer, you may receive the following C2664 error message from the compiler: ...\Program Files\Microsoft Visual Studio .NET
2003\Vc7\atlmfc\include\cstringt.h (875) : error C2664: 'PtrToStringChars' :
cannot convert parameter 1 from 'ATL:: CFixedStringMgr *' to 'const
System::String __gc *' Cannot convert an unmanaged type to a managed type
MySample.cpp(7) : see reference to function template instantiation 'ATL:
:CStringT<BaseType,StringTraits>::CStringT<ATL::CFixedStringMgr>(SystemString
*) ' being compiled with [ BaseType=char,
StringTraits=ATL::StrTraitATL<char,ATL::ChTraitsCRT<char>>,
SystemString=ATL::CFixedStringMgr ] MySample.cpp(5) : while compiling
class-template member function 'A<Stri ngType>::A(void) throw()'
with [ StringType=ATL::CAtlString ] MySample.cpp(15) : see
reference to class template instantiation 'A<Stri ngType>' being compiled
with [ StringType=ATL::CAtlString ] CAUSEYou receive this error message because the compiler matches the wrong constructor. The compiler
should match the IATLStringMgr* constructor, however, the System::String* constructor is
invoked instead. STATUSMicrosoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.WORKAROUNDWhen you call the constructor, cast the CFixedStringMgr pointer to the IAtlStringMgr pointer. The code to call the constructor is as follows:
A() throw() : CFixedStringMgr( &m_data, 1024, StrTraits::GetDefaultManager() ),
StringType( static_cast<IAtlStringMgr* >( this ) )
Note You may receive two LNK4089 linker warnings. These linker
warnings are expected, and you can safely ignore them. Use one of the following two methods to avoid
the LNK4089 warning:
- Use the linker switch /OPT:NOREF. This turns off the linker
optimizations. The result is a larger image.
- Use the linker switch /IGNORE:4089. This disables warning
LNK4089
| Modification Type: | Minor | Last Reviewed: | 1/6/2006 |
|---|
| Keywords: | kbCompiler kbbug KB328431 kbAudDeveloper |
|---|
|