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. could anybody please explain to me how come this happen?

could anybody please explain to me how come this happen?

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
8 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.
  • E Offline
    E Offline
    ewighell
    wrote on last edited by
    #1

    void fun(CArray) { } void fun(CArray& ) { } why dose the argument in the first function produce a error(like this: error C2664: 'fun' : cannot convert parameter 1 from 'class CArray' to 'class CArray'No copy constructor available for class 'CArray') while the second funtion is right? Thank you very much!!!

    S R O 3 Replies Last reply
    0
    • E ewighell

      void fun(CArray) { } void fun(CArray& ) { } why dose the argument in the first function produce a error(like this: error C2664: 'fun' : cannot convert parameter 1 from 'class CArray' to 'class CArray'No copy constructor available for class 'CArray') while the second funtion is right? Thank you very much!!!

      S Offline
      S Offline
      sunit5
      wrote on last edited by
      #2

      See the constructor CString in MSDN never say die -- modified at 4:52 Monday 2nd January, 2006

      1 Reply Last reply
      0
      • E ewighell

        void fun(CArray) { } void fun(CArray& ) { } why dose the argument in the first function produce a error(like this: error C2664: 'fun' : cannot convert parameter 1 from 'class CArray' to 'class CArray'No copy constructor available for class 'CArray') while the second funtion is right? Thank you very much!!!

        R Offline
        R Offline
        rabih_kai
        wrote on last edited by
        #3

        I've got you these from MSDN i think you will understand why? let me know in case not SYMPTOMS When a user-defined class contains a CArray and the same user-defined class is nested in another class, you may get the following errors if no copy constructor and assignment operator are provided for the class: main.cpp(52): error C2664: 'Add' : cannot convert parameter 1 from 'class B' to 'class B' No copy constructor available for class 'B' After adding a copy constructor, you get the following error message: afxtempl.h(443): error C2582:'B' : 'operator =' function is unavailable afxtempl.h(1566):while compiling class-template member function 'void __thiscall CArray::SetAtGrow(int,class B)' CAUSE If the class that contains a CArray is nested in another class, then its objects must be copied. The compiler does not construct an implicit copy constructor and copy assignment operator because the class in question has CArray as a member, which does not have a copy constructor and copy assignment operator, and CArray inherits from CObject, which has a protected copy construtor and a copy assignment operator. The compiler tries to generate the implicit ones, but that generates a call to CObject's version of them. Because they are protected, the above errors are generated. RESOLUTION You need to provide a copy constructor and an assignment operator for the class. STATUS Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article. This problem was corrected in Microsoft Visual C++ .NET. MORE INFORMATION The following example shows the correct use of the CArray class: // No compiler option needed. #include struct A { int i; int j; }; class B { public: B(); ~B(); // Need to define copy ctor and assignment operator. B(const B& b){ // Your copy ctor body goes here. } /* const B& */ void operator= (const B& b) { // Your assignment operator body goes here. } protected: CArray arrayA; }; B::B(){} B::~B(){} class C { public: C(); ~C(); void addElement(); protected: CArray arrayB; }; C::C(){} C::~C(){} void C::addElement() { B temp; arrayB.Add(temp); } void main() { } I've been programming since year 1999, graduated from Univeristy Paris 2 France, fluent in C,C++,VC++,Web programming (XML,HTML,php etc..),.NET frameworks,C# and ASP.NET,SQL server, Mastering VC++ .NET and SQL server,data structure

        E 1 Reply Last reply
        0
        • E ewighell

          void fun(CArray) { } void fun(CArray& ) { } why dose the argument in the first function produce a error(like this: error C2664: 'fun' : cannot convert parameter 1 from 'class CArray' to 'class CArray'No copy constructor available for class 'CArray') while the second funtion is right? Thank you very much!!!

          O Offline
          O Offline
          Owner drawn
          wrote on last edited by
          #4

          The first one you are passing by value. So a copy constructor is required. The second one you are passing by reference so no copy constructor is required. Only the reference is passed.

          Jesus Loves You and Me :)

          --Owner Drawn --Nothing special --Defeat is temporary but surrender is permanent --Never say quits --Jesus is Lord

          E 1 Reply Last reply
          0
          • R rabih_kai

            I've got you these from MSDN i think you will understand why? let me know in case not SYMPTOMS When a user-defined class contains a CArray and the same user-defined class is nested in another class, you may get the following errors if no copy constructor and assignment operator are provided for the class: main.cpp(52): error C2664: 'Add' : cannot convert parameter 1 from 'class B' to 'class B' No copy constructor available for class 'B' After adding a copy constructor, you get the following error message: afxtempl.h(443): error C2582:'B' : 'operator =' function is unavailable afxtempl.h(1566):while compiling class-template member function 'void __thiscall CArray::SetAtGrow(int,class B)' CAUSE If the class that contains a CArray is nested in another class, then its objects must be copied. The compiler does not construct an implicit copy constructor and copy assignment operator because the class in question has CArray as a member, which does not have a copy constructor and copy assignment operator, and CArray inherits from CObject, which has a protected copy construtor and a copy assignment operator. The compiler tries to generate the implicit ones, but that generates a call to CObject's version of them. Because they are protected, the above errors are generated. RESOLUTION You need to provide a copy constructor and an assignment operator for the class. STATUS Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article. This problem was corrected in Microsoft Visual C++ .NET. MORE INFORMATION The following example shows the correct use of the CArray class: // No compiler option needed. #include struct A { int i; int j; }; class B { public: B(); ~B(); // Need to define copy ctor and assignment operator. B(const B& b){ // Your copy ctor body goes here. } /* const B& */ void operator= (const B& b) { // Your assignment operator body goes here. } protected: CArray arrayA; }; B::B(){} B::~B(){} class C { public: C(); ~C(); void addElement(); protected: CArray arrayB; }; C::C(){} C::~C(){} void C::addElement() { B temp; arrayB.Add(temp); } void main() { } I've been programming since year 1999, graduated from Univeristy Paris 2 France, fluent in C,C++,VC++,Web programming (XML,HTML,php etc..),.NET frameworks,C# and ASP.NET,SQL server, Mastering VC++ .NET and SQL server,data structure

            E Offline
            E Offline
            ewighell
            wrote on last edited by
            #5

            I got it,thank you very much. I am a beginner of programming, I found that a lot of people like you can always find answers to questions quickly and correctly from on the Internet especially microsoft's web site. could you please tell me how you do that ? is there relatively any way to follow? or is any books or articles teaching these things you can recommend to me? Thank you again!! ------------------- I am learning C++ and English

            R 1 Reply Last reply
            0
            • O Owner drawn

              The first one you are passing by value. So a copy constructor is required. The second one you are passing by reference so no copy constructor is required. Only the reference is passed.

              Jesus Loves You and Me :)

              --Owner Drawn --Nothing special --Defeat is temporary but surrender is permanent --Never say quits --Jesus is Lord

              E Offline
              E Offline
              ewighell
              wrote on last edited by
              #6

              Thank you very much!!! ------------------- I am learning C++ and English

              1 Reply Last reply
              0
              • E ewighell

                I got it,thank you very much. I am a beginner of programming, I found that a lot of people like you can always find answers to questions quickly and correctly from on the Internet especially microsoft's web site. could you please tell me how you do that ? is there relatively any way to follow? or is any books or articles teaching these things you can recommend to me? Thank you again!! ------------------- I am learning C++ and English

                R Offline
                R Offline
                rabih_kai
                wrote on last edited by
                #7

                Dear, you can visit microsft.msdn.com, that is full of help, or simply use MSDN help that comes with Visual studio 6.0 ,2003 or 2005, just search for the error number and the whole help will be yours serving your needs, I was using C++ for 7 years, trust me go for C# and never for J#. C# is easier, has the same libraries and more rich GUI wise. I've been programming since year 1999, graduated from Univeristy Paris 2 France, fluent in C,C++,VC++,Web programming (XML,HTML,php etc..),.NET frameworks,C# and ASP.NET,SQL server, Mastering VC++ .NET and SQL server,data structure and database design

                E 1 Reply Last reply
                0
                • R rabih_kai

                  Dear, you can visit microsft.msdn.com, that is full of help, or simply use MSDN help that comes with Visual studio 6.0 ,2003 or 2005, just search for the error number and the whole help will be yours serving your needs, I was using C++ for 7 years, trust me go for C# and never for J#. C# is easier, has the same libraries and more rich GUI wise. I've been programming since year 1999, graduated from Univeristy Paris 2 France, fluent in C,C++,VC++,Web programming (XML,HTML,php etc..),.NET frameworks,C# and ASP.NET,SQL server, Mastering VC++ .NET and SQL server,data structure and database design

                  E Offline
                  E Offline
                  ewighell
                  wrote on last edited by
                  #8

                  Thank you very much!!! ------------------- I am learning C++ and English

                  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