CString Error Compiling With Visual Studio.NET (VC7)
-
Has anyone experienced CString problems re-compiling an existing application with VC.NET I got the following errors while re-compiling an existing application with VC.NET/VS7. The application compiles and works perfectly with VS6. Yes, I am aware of the new string library (atlstr.h), but was suprised to get compilation errors on the older MFC CString. class CString; ... ... (CString forward-declared in a header - no change from existing code) error C2371: 'CString' : redefinition; different basic types int DisplayRecord( _RecordsetPtr recordset, const CString& strFilterColumnName = "", const CString& strFilterColumnValue = "", const CString& strDupColumnName = "", const CString& strDateFormat = szFTDateFormat); C2440: 'default argument' : cannot convert from 'char [1]' to 'const CString &' When I re-compile the application with VS6, it works fine. I cannot imagine having to embark on a porting exercise just to remove all the older MFC CString references in my code. Has anyone experienced the same problems, and how did they resolve it. Gaul www.gaulles.com
-
Has anyone experienced CString problems re-compiling an existing application with VC.NET I got the following errors while re-compiling an existing application with VC.NET/VS7. The application compiles and works perfectly with VS6. Yes, I am aware of the new string library (atlstr.h), but was suprised to get compilation errors on the older MFC CString. class CString; ... ... (CString forward-declared in a header - no change from existing code) error C2371: 'CString' : redefinition; different basic types int DisplayRecord( _RecordsetPtr recordset, const CString& strFilterColumnName = "", const CString& strFilterColumnValue = "", const CString& strDupColumnName = "", const CString& strDateFormat = szFTDateFormat); C2440: 'default argument' : cannot convert from 'char [1]' to 'const CString &' When I re-compile the application with VS6, it works fine. I cannot imagine having to embark on a porting exercise just to remove all the older MFC CString references in my code. Has anyone experienced the same problems, and how did they resolve it. Gaul www.gaulles.com
Hi, just wondering that it is possible to change the value of a const(!) ref. under VS6 ?!? cu, Jens
-
Has anyone experienced CString problems re-compiling an existing application with VC.NET I got the following errors while re-compiling an existing application with VC.NET/VS7. The application compiles and works perfectly with VS6. Yes, I am aware of the new string library (atlstr.h), but was suprised to get compilation errors on the older MFC CString. class CString; ... ... (CString forward-declared in a header - no change from existing code) error C2371: 'CString' : redefinition; different basic types int DisplayRecord( _RecordsetPtr recordset, const CString& strFilterColumnName = "", const CString& strFilterColumnValue = "", const CString& strDupColumnName = "", const CString& strDateFormat = szFTDateFormat); C2440: 'default argument' : cannot convert from 'char [1]' to 'const CString &' When I re-compile the application with VS6, it works fine. I cannot imagine having to embark on a porting exercise just to remove all the older MFC CString references in my code. Has anyone experienced the same problems, and how did they resolve it. Gaul www.gaulles.com
Here's my guess: Your error is that you're trying to create a reference to something that isn't a CString. If the parameter were a plain CString, the compiler could call the appropriate constructor when the function was called. But since creating a reference doesn't call a constructor, there's no way to convert from a char array to a CString. Look in the docs for a list of changes between VC6 and 7 and see if it mentions this. --Mike-- http://home.inreach.com/mdunn/ Sometimes, arming yourself with a big pointy stake just won't do you any good.
-
Has anyone experienced CString problems re-compiling an existing application with VC.NET I got the following errors while re-compiling an existing application with VC.NET/VS7. The application compiles and works perfectly with VS6. Yes, I am aware of the new string library (atlstr.h), but was suprised to get compilation errors on the older MFC CString. class CString; ... ... (CString forward-declared in a header - no change from existing code) error C2371: 'CString' : redefinition; different basic types int DisplayRecord( _RecordsetPtr recordset, const CString& strFilterColumnName = "", const CString& strFilterColumnValue = "", const CString& strDupColumnName = "", const CString& strDateFormat = szFTDateFormat); C2440: 'default argument' : cannot convert from 'char [1]' to 'const CString &' When I re-compile the application with VS6, it works fine. I cannot imagine having to embark on a porting exercise just to remove all the older MFC CString references in my code. Has anyone experienced the same problems, and how did they resolve it. Gaul www.gaulles.com
It's generally a bad idea to convert one object (or type) to a reference to another object (unless there is an explicit operator for such conversion). While assignment CString str = "" works fine, statement CString& str = "" will lead to an error. Visual C++ 6.0 is based on older compiler version and does not react on many erroneous statements. VC++ Embedded 3.0 is much better in this respect. VC++ 7.0 is even newer, so it shouldn't be surprising that it is more strict. Win32/ATL/MFC Developer Oslo, Norway
-
Hi, just wondering that it is possible to change the value of a const(!) ref. under VS6 ?!? cu, Jens
Those are default parameter values set for the function declaration in the header file. Works with VS6. Gaul www.gaulles.com
-
It's generally a bad idea to convert one object (or type) to a reference to another object (unless there is an explicit operator for such conversion). While assignment CString str = "" works fine, statement CString& str = "" will lead to an error. Visual C++ 6.0 is based on older compiler version and does not react on many erroneous statements. VC++ Embedded 3.0 is much better in this respect. VC++ 7.0 is even newer, so it shouldn't be surprising that it is more strict. Win32/ATL/MFC Developer Oslo, Norway
What about the earlier error, reproduced below. CString is just the regular CString - no special class. class CString; ... ... (CString forward-declared in a header - no change from existing code) error C2371: 'CString' : redefinition; different basic types Gaul www.gaulles.com
-
Here's my guess: Your error is that you're trying to create a reference to something that isn't a CString. If the parameter were a plain CString, the compiler could call the appropriate constructor when the function was called. But since creating a reference doesn't call a constructor, there's no way to convert from a char array to a CString. Look in the docs for a list of changes between VC6 and 7 and see if it mentions this. --Mike-- http://home.inreach.com/mdunn/ Sometimes, arming yourself with a big pointy stake just won't do you any good.
CString is just a regular CString - no special class. What about the following error: class CString; ... ... (regular CString forward-declared in a header - no change from existing code) error C2371: 'CString' : redefinition; different basic types Gaul www.gaulles.com
-
What about the earlier error, reproduced below. CString is just the regular CString - no special class. class CString; ... ... (CString forward-declared in a header - no change from existing code) error C2371: 'CString' : redefinition; different basic types Gaul www.gaulles.com
I don't have with me VS.Net headers now, but if I remember it right, CString is no longer defined as class, it is template-based now. This will of course make compiler complain about forward-declaring CString as class. Forward declaration must match the actual declaration exactly: you can't refer struct and template as class. I advice you to take a closer look at VC header files. Spending some time on reading class library header files will save you many hours of work in the future. Good luck Vagif Win32/ATL/MFC Developer Oslo, Norway
-
Has anyone experienced CString problems re-compiling an existing application with VC.NET I got the following errors while re-compiling an existing application with VC.NET/VS7. The application compiles and works perfectly with VS6. Yes, I am aware of the new string library (atlstr.h), but was suprised to get compilation errors on the older MFC CString. class CString; ... ... (CString forward-declared in a header - no change from existing code) error C2371: 'CString' : redefinition; different basic types int DisplayRecord( _RecordsetPtr recordset, const CString& strFilterColumnName = "", const CString& strFilterColumnValue = "", const CString& strDupColumnName = "", const CString& strDateFormat = szFTDateFormat); C2440: 'default argument' : cannot convert from 'char [1]' to 'const CString &' When I re-compile the application with VS6, it works fine. I cannot imagine having to embark on a porting exercise just to remove all the older MFC CString references in my code. Has anyone experienced the same problems, and how did they resolve it. Gaul www.gaulles.com
I haven't worked with .NET at all, so this may not be relevant! CString is actually two different types IN VC6 - depending upon the #define _UNICODE state it is either an 'char' container, or a 'wchar_t' container. It is possible to get the "redefinition; different basic types" error if you try to mix 'ASCII' and 'UNICODE' compiled files. Could the .NET error be some problem related to UNICODE and non-UNICODE code interacting ?
-
I haven't worked with .NET at all, so this may not be relevant! CString is actually two different types IN VC6 - depending upon the #define _UNICODE state it is either an 'char' container, or a 'wchar_t' container. It is possible to get the "redefinition; different basic types" error if you try to mix 'ASCII' and 'UNICODE' compiled files. Could the .NET error be some problem related to UNICODE and non-UNICODE code interacting ?
Actually, just reviewing your post again I am fairly sure that this is a UNICODE problem! You are assigning default values to the parameters of the fuintion call. The default values are all ASCII string literals eg: const CString& param1 = "" If the default .NET compilation is UNICODE then this will fail, since you cannot initialise a UNICODE CString with an ASCII literal. For UNICODE, the code should read const CString& param1 = L"" Or, if you want to not worry about this: const CString& param1 = _T("") So, the bottom line is that the code you are trying to compile can ONLY be compiled in non-UNICODE mode - it is not UNICODE aware. Therefore, you have to make sure that .NET is not running in UNICODE mode (I assume it's an option ? Java only supports UNICODE, so there is no 'non-UNICODE' mode)