Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. The Lounge
  3. CString Error Compiling With Visual Studio.NET (VC7)

CString Error Compiling With Visual Studio.NET (VC7)

Scheduled Pinned Locked Moved The Lounge
csharpc++visual-studiocomhelp
10 Posts 5 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gaul
    wrote on last edited by
    #1

    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

    J M V M 4 Replies Last reply
    0
    • G Gaul

      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

      J Offline
      J Offline
      Jens Kreiensiek
      wrote on last edited by
      #2

      Hi, just wondering that it is possible to change the value of a const(!) ref. under VS6 ?!? cu, Jens

      G 1 Reply Last reply
      0
      • G Gaul

        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

        M Offline
        M Offline
        Michael Dunn
        wrote on last edited by
        #3

        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.

        G 1 Reply Last reply
        0
        • G Gaul

          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

          V Offline
          V Offline
          Vagif Abilov
          wrote on last edited by
          #4

          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

          G 1 Reply Last reply
          0
          • J Jens Kreiensiek

            Hi, just wondering that it is possible to change the value of a const(!) ref. under VS6 ?!? cu, Jens

            G Offline
            G Offline
            Gaul
            wrote on last edited by
            #5

            Those are default parameter values set for the function declaration in the header file. Works with VS6. Gaul www.gaulles.com

            1 Reply Last reply
            0
            • V Vagif Abilov

              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

              G Offline
              G Offline
              Gaul
              wrote on last edited by
              #6

              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

              V 1 Reply Last reply
              0
              • M Michael Dunn

                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.

                G Offline
                G Offline
                Gaul
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                • G Gaul

                  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

                  V Offline
                  V Offline
                  Vagif Abilov
                  wrote on last edited by
                  #8

                  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

                  1 Reply Last reply
                  0
                  • G Gaul

                    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

                    M Offline
                    M Offline
                    Mike Burston
                    wrote on last edited by
                    #9

                    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 ?

                    M 1 Reply Last reply
                    0
                    • M Mike Burston

                      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 ?

                      M Offline
                      M Offline
                      Mike Burston
                      wrote on last edited by
                      #10

                      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)

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups