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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. problem on work with Class CArray [modified]

problem on work with Class CArray [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
23 Posts 4 Posters 0 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.
  • I Offline
    I Offline
    Immunity18
    wrote on last edited by
    #1

    got 2 function ( second is executed inside first one) how i will pass the CArray class? with my code 1 error : error C2664: 'GetDF' : cannot convert parameter 1 from 'class CArray' to 'class CArray' No copy constructor available for class 'CArray' Error executing cl.exe.

    double CAnaktisiDlg::FindDF(CString file , CArray < CString, CString > AFArray)
    {
    		CString LineRead ;
    		CString str7;
    		CString FilePathName;
    		const int sz =100;
    		char buf[sz];
    		FilePathName = m_FolderName + file;
    		ifstream FileText(FilePathName);
    		while(FileText.get(buf,sz))
    		{
    			FileText.get();
    			LineRead = (LPCSTR) buf;
    			GetDFArray(LineRead);
    			GetDF(AFArray);
    	
    		}
    		FileText.close();	
    	return 0.0;
    }
    
    void CAnaktisiDlg::GetDF(CArray < CString , CString > FArray)
    {
    	int nDf=0;
    	int niDF = 0;
    	for ( int i = 0 ; i
    
    M S J 4 Replies Last reply
    0
    • I Immunity18

      got 2 function ( second is executed inside first one) how i will pass the CArray class? with my code 1 error : error C2664: 'GetDF' : cannot convert parameter 1 from 'class CArray' to 'class CArray' No copy constructor available for class 'CArray' Error executing cl.exe.

      double CAnaktisiDlg::FindDF(CString file , CArray < CString, CString > AFArray)
      {
      		CString LineRead ;
      		CString str7;
      		CString FilePathName;
      		const int sz =100;
      		char buf[sz];
      		FilePathName = m_FolderName + file;
      		ifstream FileText(FilePathName);
      		while(FileText.get(buf,sz))
      		{
      			FileText.get();
      			LineRead = (LPCSTR) buf;
      			GetDFArray(LineRead);
      			GetDF(AFArray);
      	
      		}
      		FileText.close();	
      	return 0.0;
      }
      
      void CAnaktisiDlg::GetDF(CArray < CString , CString > FArray)
      {
      	int nDf=0;
      	int niDF = 0;
      	for ( int i = 0 ; i
      
      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      You should pass a reference to the array. You're trying to pass an array object which requires a copy constructor the compiler needs to create a temporary object to pass to the other function. If that's your intent then you'd need to make a CArray-derived class with valid copy semantics. Mark

      "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

      I 1 Reply Last reply
      0
      • I Immunity18

        got 2 function ( second is executed inside first one) how i will pass the CArray class? with my code 1 error : error C2664: 'GetDF' : cannot convert parameter 1 from 'class CArray' to 'class CArray' No copy constructor available for class 'CArray' Error executing cl.exe.

        double CAnaktisiDlg::FindDF(CString file , CArray < CString, CString > AFArray)
        {
        		CString LineRead ;
        		CString str7;
        		CString FilePathName;
        		const int sz =100;
        		char buf[sz];
        		FilePathName = m_FolderName + file;
        		ifstream FileText(FilePathName);
        		while(FileText.get(buf,sz))
        		{
        			FileText.get();
        			LineRead = (LPCSTR) buf;
        			GetDFArray(LineRead);
        			GetDF(AFArray);
        	
        		}
        		FileText.close();	
        	return 0.0;
        }
        
        void CAnaktisiDlg::GetDF(CArray < CString , CString > FArray)
        {
        	int nDf=0;
        	int niDF = 0;
        	for ( int i = 0 ; i
        
        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        You may also want to define your array class like CArray < CString, CString & > so unnecessary copies of a CString for temporary objects aren't created every time you access the container. Mark

        "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

        I 1 Reply Last reply
        0
        • M Mark Salsbery

          You should pass a reference to the array. You're trying to pass an array object which requires a copy constructor the compiler needs to create a temporary object to pass to the other function. If that's your intent then you'd need to make a CArray-derived class with valid copy semantics. Mark

          "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

          I Offline
          I Offline
          Immunity18
          wrote on last edited by
          #4

          :S too much C specific words for me :(( hear what i want to do :D i had create a CArray class to store CString (Filenames) because i dont know how many Files will be each time (so i cant use static Array[] ) so i want to pass the CArray in each function so i can do some things in these functions :D

          M 1 Reply Last reply
          0
          • M Mark Salsbery

            You may also want to define your array class like CArray < CString, CString & > so unnecessary copies of a CString for temporary objects aren't created every time you access the container. Mark

            "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

            I Offline
            I Offline
            Immunity18
            wrote on last edited by
            #5

            thanks i think i fix it :D i put CArray < CString , CString& > &FArray am i write ? :D (for the moment no error in compiler :D)

            M 1 Reply Last reply
            0
            • I Immunity18

              :S too much C specific words for me :(( hear what i want to do :D i had create a CArray class to store CString (Filenames) because i dont know how many Files will be each time (so i cant use static Array[] ) so i want to pass the CArray in each function so i can do some things in these functions :D

              M Offline
              M Offline
              Mark Salsbery
              wrote on last edited by
              #6

              Right :) But you should probably pass the array by reference (or you could use a pointer to the array). Otherwise, like all function calls, a temporary array object needs to be created to pass to a function every time you call one. That's a bit inefficient and unnecessary. :) Actually, these are C++ specific words ;P double CAnaktisiDlg::FindDF(CString file , CArray < CString, CString > &AFArray) ... void CAnaktisiDlg::GetDF(CArray < CString , CString > &FArray) ...

              "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

              1 Reply Last reply
              0
              • I Immunity18

                thanks i think i fix it :D i put CArray < CString , CString& > &FArray am i write ? :D (for the moment no error in compiler :D)

                M Offline
                M Offline
                Mark Salsbery
                wrote on last edited by
                #7

                Yes! That'll work for your function passed parameters. Make sure the actual array object you are passing is created the same way: // Create a CArray < CString , CString& > called MyStringArray CArray < CString , CString& > MyStringArray; ... // Call a method/function passing the array by reference double retval = FindDF(filestr , MyStringArray);

                "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

                I 1 Reply Last reply
                0
                • M Mark Salsbery

                  Yes! That'll work for your function passed parameters. Make sure the actual array object you are passing is created the same way: // Create a CArray < CString , CString& > called MyStringArray CArray < CString , CString& > MyStringArray; ... // Call a method/function passing the array by reference double retval = FindDF(filestr , MyStringArray);

                  "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

                  I Offline
                  I Offline
                  Immunity18
                  wrote on last edited by
                  #8

                  :D i create the CArray in parent function as CArray FArray; how i have to pass it in the parametr of function ? :D

                  M 1 Reply Last reply
                  0
                  • I Immunity18

                    :D i create the CArray in parent function as CArray FArray; how i have to pass it in the parametr of function ? :D

                    M Offline
                    M Offline
                    Mark Salsbery
                    wrote on last edited by
                    #9

                    Immunity18 wrote:

                    i create the CArray in parent function as CArray FArray;

                    Did you leave out the angle brackets on purpose or by accident. That should be CArray < CString , CString& > FArray;

                    "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

                    I 1 Reply Last reply
                    0
                    • M Mark Salsbery

                      Immunity18 wrote:

                      i create the CArray in parent function as CArray FArray;

                      Did you leave out the angle brackets on purpose or by accident. That should be CArray < CString , CString& > FArray;

                      "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

                      I Offline
                      I Offline
                      Immunity18
                      wrote on last edited by
                      #10

                      CArray < CString , CString > FArray; so i have to go and correct it the second CString ==> CString& or can I work with that style ?

                      M 1 Reply Last reply
                      0
                      • I Immunity18

                        CArray < CString , CString > FArray; so i have to go and correct it the second CString ==> CString& or can I work with that style ?

                        M Offline
                        M Offline
                        Mark Salsbery
                        wrote on last edited by
                        #11

                        Immunity18 wrote:

                        and correct it the second CString ==> CString&

                        Yes. It needs to be the same everywhere you use the template definition. That's why a typedef can simplify things. A typedef creates an alias to the type: typedef CArray< CString , CString &> CMyStringArray; Now you can use "CMyStringArray" instead of "CArray< CString , CString &>" everywhere...

                        typedef CArray< CString , CString &> CMyStringArray;
                        ...
                        double CAnaktisiDlg::FindDF(CString file , CMyStringArray &AFArray)
                        ...
                        void CAnaktisiDlg::GetDF(CMyStringArray &FArray)
                        ...
                        CMyStringArray FArray;
                        ...
                        // Call a method/function passing FArray by reference
                        double retval = FindDF(filestr , FArray);

                        Makes it cleaner to read IMO but you're free to use the long version of course :) Mark

                        "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

                        I 2 Replies Last reply
                        0
                        • M Mark Salsbery

                          Immunity18 wrote:

                          and correct it the second CString ==> CString&

                          Yes. It needs to be the same everywhere you use the template definition. That's why a typedef can simplify things. A typedef creates an alias to the type: typedef CArray< CString , CString &> CMyStringArray; Now you can use "CMyStringArray" instead of "CArray< CString , CString &>" everywhere...

                          typedef CArray< CString , CString &> CMyStringArray;
                          ...
                          double CAnaktisiDlg::FindDF(CString file , CMyStringArray &AFArray)
                          ...
                          void CAnaktisiDlg::GetDF(CMyStringArray &FArray)
                          ...
                          CMyStringArray FArray;
                          ...
                          // Call a method/function passing FArray by reference
                          double retval = FindDF(filestr , FArray);

                          Makes it cleaner to read IMO but you're free to use the long version of course :) Mark

                          "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

                          I Offline
                          I Offline
                          Immunity18
                          wrote on last edited by
                          #12

                          ok i try to do as you command !:D but where i will put typedef ? in .h ? (for the moment i put it in .cpp ) and i will put it where the #includes or where the are the other declarations

                          1 Reply Last reply
                          0
                          • M Mark Salsbery

                            Immunity18 wrote:

                            and correct it the second CString ==> CString&

                            Yes. It needs to be the same everywhere you use the template definition. That's why a typedef can simplify things. A typedef creates an alias to the type: typedef CArray< CString , CString &> CMyStringArray; Now you can use "CMyStringArray" instead of "CArray< CString , CString &>" everywhere...

                            typedef CArray< CString , CString &> CMyStringArray;
                            ...
                            double CAnaktisiDlg::FindDF(CString file , CMyStringArray &AFArray)
                            ...
                            void CAnaktisiDlg::GetDF(CMyStringArray &FArray)
                            ...
                            CMyStringArray FArray;
                            ...
                            // Call a method/function passing FArray by reference
                            double retval = FindDF(filestr , FArray);

                            Makes it cleaner to read IMO but you're free to use the long version of course :) Mark

                            "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

                            I Offline
                            I Offline
                            Immunity18
                            wrote on last edited by
                            #13

                            I have in project.h void GetDF( CMyStringArray &FArray); double FindDF(CString file , CMyStringArray &AFArray); and it pop up me errors error C2061: syntax error : identifier 'CMyStringArray'

                            M 1 Reply Last reply
                            0
                            • I Immunity18

                              I have in project.h void GetDF( CMyStringArray &FArray); double FindDF(CString file , CMyStringArray &AFArray); and it pop up me errors error C2061: syntax error : identifier 'CMyStringArray'

                              M Offline
                              M Offline
                              Mark Salsbery
                              wrote on last edited by
                              #14

                              The typedef needs to be visible to any point in the code it is used - Any .h file will do, or even at the bottom of your stdafx.h precompiled header file if it's used all over the place :) Mark

                              "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

                              I 2 Replies Last reply
                              0
                              • M Mark Salsbery

                                The typedef needs to be visible to any point in the code it is used - Any .h file will do, or even at the bottom of your stdafx.h precompiled header file if it's used all over the place :) Mark

                                "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

                                I Offline
                                I Offline
                                Immunity18
                                wrote on last edited by
                                #15

                                plx plx noob specific language ! :D

                                M 1 Reply Last reply
                                0
                                • M Mark Salsbery

                                  The typedef needs to be visible to any point in the code it is used - Any .h file will do, or even at the bottom of your stdafx.h precompiled header file if it's used all over the place :) Mark

                                  "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

                                  I Offline
                                  I Offline
                                  Immunity18
                                  wrote on last edited by
                                  #16

                                  ooooooo ! I leveled up ! \o/ its ok i put it in bottom of stafx.h and works fine :D thanks again ! mark

                                  M 2 Replies Last reply
                                  0
                                  • I Immunity18

                                    plx plx noob specific language ! :D

                                    M Offline
                                    M Offline
                                    Mark Salsbery
                                    wrote on last edited by
                                    #17

                                    The compiler works top-down - so if you refer to some defined type (class, struct, typedef alias, #define, etc) then the definitition needs to be above the code that refers to it. That way the compiler already knows what it means when it sees it. Typically there's a precompiled header file to make builds faster. Typically this file is called stdafx.h. In there is all the common stuff used throughout a project so it's a good place to put anything you want "seen" by the compiler throughout the project. In your example, if the only place you are reffering to "CMyStringArray" is in one header file then you could just put the typedef near the top of that file. Make sense? Mark

                                    "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

                                    I 1 Reply Last reply
                                    0
                                    • M Mark Salsbery

                                      The compiler works top-down - so if you refer to some defined type (class, struct, typedef alias, #define, etc) then the definitition needs to be above the code that refers to it. That way the compiler already knows what it means when it sees it. Typically there's a precompiled header file to make builds faster. Typically this file is called stdafx.h. In there is all the common stuff used throughout a project so it's a good place to put anything you want "seen" by the compiler throughout the project. In your example, if the only place you are reffering to "CMyStringArray" is in one header file then you could just put the typedef near the top of that file. Make sense? Mark

                                      "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

                                      I Offline
                                      I Offline
                                      Immunity18
                                      wrote on last edited by
                                      #18

                                      yes yes as my before reply i did it :D I leveled up from 100%noob to 80%noob :D

                                      1 Reply Last reply
                                      0
                                      • I Immunity18

                                        ooooooo ! I leveled up ! \o/ its ok i put it in bottom of stafx.h and works fine :D thanks again ! mark

                                        M Offline
                                        M Offline
                                        Mark Salsbery
                                        wrote on last edited by
                                        #19

                                        :laugh: leveled up or down!? You're welcome! Mark

                                        "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

                                        1 Reply Last reply
                                        0
                                        • I Immunity18

                                          ooooooo ! I leveled up ! \o/ its ok i put it in bottom of stafx.h and works fine :D thanks again ! mark

                                          M Offline
                                          M Offline
                                          Mark Salsbery
                                          wrote on last edited by
                                          #20

                                          Oh wait, you said percent noob - that would be up! :)

                                          "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

                                          I 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