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. how to derive a CArray method

how to derive a CArray method

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
16 Posts 8 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.
  • L lucy 0

    I have a member variable declared as: CArray m_dotArray; When I am using it, I use CArray::Add to add new dots to it. But I don't want to add duplicate dot, so I derived CMyArray in the following manner:

    template <class TYPE, class ARG_TYPE>
    class CMyArray : public CArray < TYPE, ARG_TYPE >
    {
    public:
    int AddThis(ARG_TYPE newElement);
    };

    template < class TYPE, class ARG_TYPE >
    int CMyArray < TYPE, ARG_TYPE > ::AddThis(ARG_TYPE newElement)
    {
    ARG_TYPE existingElement;
    for ( int i = 0; i < GetSize(); i ++ )
    {
    existingElement = GetAt(i);
    if ( existiingElement == newElement )
    return -1;
    }
    Add(newElement);
    return 0;
    }

    but when compiling the following error is reported: error LNK2001: unresolved external symbol "public: int __thiscall CMyArray < class CPoint, class CPoint > ::AddThis(class CPoint)" ...... What did I miss? :confused: TIA!!

    C Offline
    C Offline
    Christian Graus
    wrote on last edited by
    #2

    Is this code visible to your project ? Is it part of your project ? Have you ever tried std::vector ? Unlike CArray, it's powerful, flexible and does not suck. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
    C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002
    Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002

    L T 2 Replies Last reply
    0
    • C Christian Graus

      Is this code visible to your project ? Is it part of your project ? Have you ever tried std::vector ? Unlike CArray, it's powerful, flexible and does not suck. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
      C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002
      Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002

      L Offline
      L Offline
      lucy 0
      wrote on last edited by
      #3

      yes, I have added both the .h and .cpp to my project. Also, I have include the header file when I declare the member variable. I did a few Build->Clean and Rebuild All, in the hope of getting rid of this problem. But without any success. X| I didn't know anything about std::vector, I would try to read something about it. Before that, what is the correct way of deriving any class from CArray? I think I am not following the correct syntax. :(

      C 1 Reply Last reply
      0
      • L lucy 0

        yes, I have added both the .h and .cpp to my project. Also, I have include the header file when I declare the member variable. I did a few Build->Clean and Rebuild All, in the hope of getting rid of this problem. But without any success. X| I didn't know anything about std::vector, I would try to read something about it. Before that, what is the correct way of deriving any class from CArray? I think I am not following the correct syntax. :(

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #4

        If you search for 'vector graus' in the articles you should find my article on vectors. I don't know how you would derive from CArray. I'd probably try to contain a CArray instead and see if that worked, assuming I had to. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
        C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002
        Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002

        1 Reply Last reply
        0
        • L lucy 0

          I have a member variable declared as: CArray m_dotArray; When I am using it, I use CArray::Add to add new dots to it. But I don't want to add duplicate dot, so I derived CMyArray in the following manner:

          template <class TYPE, class ARG_TYPE>
          class CMyArray : public CArray < TYPE, ARG_TYPE >
          {
          public:
          int AddThis(ARG_TYPE newElement);
          };

          template < class TYPE, class ARG_TYPE >
          int CMyArray < TYPE, ARG_TYPE > ::AddThis(ARG_TYPE newElement)
          {
          ARG_TYPE existingElement;
          for ( int i = 0; i < GetSize(); i ++ )
          {
          existingElement = GetAt(i);
          if ( existiingElement == newElement )
          return -1;
          }
          Add(newElement);
          return 0;
          }

          but when compiling the following error is reported: error LNK2001: unresolved external symbol "public: int __thiscall CMyArray < class CPoint, class CPoint > ::AddThis(class CPoint)" ...... What did I miss? :confused: TIA!!

          N Offline
          N Offline
          Nitron
          wrote on last edited by
          #5

          I'm with Cristian. std::vector is the way to go. - Nitron


          "Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb

          1 Reply Last reply
          0
          • L lucy 0

            I have a member variable declared as: CArray m_dotArray; When I am using it, I use CArray::Add to add new dots to it. But I don't want to add duplicate dot, so I derived CMyArray in the following manner:

            template <class TYPE, class ARG_TYPE>
            class CMyArray : public CArray < TYPE, ARG_TYPE >
            {
            public:
            int AddThis(ARG_TYPE newElement);
            };

            template < class TYPE, class ARG_TYPE >
            int CMyArray < TYPE, ARG_TYPE > ::AddThis(ARG_TYPE newElement)
            {
            ARG_TYPE existingElement;
            for ( int i = 0; i < GetSize(); i ++ )
            {
            existingElement = GetAt(i);
            if ( existiingElement == newElement )
            return -1;
            }
            Add(newElement);
            return 0;
            }

            but when compiling the following error is reported: error LNK2001: unresolved external symbol "public: int __thiscall CMyArray < class CPoint, class CPoint > ::AddThis(class CPoint)" ...... What did I miss? :confused: TIA!!

            D Offline
            D Offline
            Dave Bryant
            wrote on last edited by
            #6

            Is the function implementation in the header file (or a #included inline file)? If it is in a .cpp file, then the compiler won't find it when instantiating the template, and so the function will be missing at link-time. Dave

            L 1 Reply Last reply
            0
            • D Dave Bryant

              Is the function implementation in the header file (or a #included inline file)? If it is in a .cpp file, then the compiler won't find it when instantiating the template, and so the function will be missing at link-time. Dave

              L Offline
              L Offline
              lucy 0
              wrote on last edited by
              #7

              ah Yes. I implemented it in cpp file. After I delete the cpp and move the function definition to the .h file, everything is okay. Thank you so much! :laugh::laugh: I am so happy.

              T 1 Reply Last reply
              0
              • C Christian Graus

                Is this code visible to your project ? Is it part of your project ? Have you ever tried std::vector ? Unlike CArray, it's powerful, flexible and does not suck. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
                C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002
                Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002

                T Offline
                T Offline
                Tim Smith
                wrote on last edited by
                #8

                std::vector - code bloat... CAtlArray :) Tim Smith I'm going to patent thought. I have yet to see any prior art.

                L C 2 Replies Last reply
                0
                • L lucy 0

                  ah Yes. I implemented it in cpp file. After I delete the cpp and move the function definition to the .h file, everything is okay. Thank you so much! :laugh::laugh: I am so happy.

                  T Offline
                  T Offline
                  Tim Smith
                  wrote on last edited by
                  #9

                  Thank god someone answered your QUESTION. The style police should take a rest. :) Tim Smith I'm going to patent thought. I have yet to see any prior art.

                  G C 2 Replies Last reply
                  0
                  • T Tim Smith

                    std::vector - code bloat... CAtlArray :) Tim Smith I'm going to patent thought. I have yet to see any prior art.

                    L Offline
                    L Offline
                    lucy 0
                    wrote on last edited by
                    #10

                    CAtlArray, hmm, I should keep it in mind for future use, since I don't need the serialization function here at all. Thank you. :)

                    1 Reply Last reply
                    0
                    • T Tim Smith

                      std::vector - code bloat... CAtlArray :) Tim Smith I'm going to patent thought. I have yet to see any prior art.

                      C Offline
                      C Offline
                      Christian Graus
                      wrote on last edited by
                      #11

                      lol - you just don't give up, do you ? I've never used CAtlArray, is it part of WTL ? How complete is it ? That is, does it offer algorithms etc, or is it merely another container of the sort I could write in an afternoon ? Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
                      C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002
                      Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002

                      C 1 Reply Last reply
                      0
                      • T Tim Smith

                        Thank god someone answered your QUESTION. The style police should take a rest. :) Tim Smith I'm going to patent thought. I have yet to see any prior art.

                        G Offline
                        G Offline
                        Gary Kirkham
                        wrote on last edited by
                        #12

                        Like you, I have noticed that there are a lot of posters that preach certain methods for doing specfic tasks. While, I think it is OK to provide alternative appoaches to solve a problem...I also think that you should try to answer the question, as posed. Gary Kirkham A working Program is one that has only unobserved bugs

                        1 Reply Last reply
                        0
                        • T Tim Smith

                          Thank god someone answered your QUESTION. The style police should take a rest. :) Tim Smith I'm going to patent thought. I have yet to see any prior art.

                          C Offline
                          C Offline
                          Christian Graus
                          wrote on last edited by
                          #13

                          Be fair - I NEVER recommend STL unless I can also answer the question, or the question has been answered. I may not have got it right, but I had a guess. And the MFC container classes are still a pile of fetid refuse. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
                          C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002
                          Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002

                          A 1 Reply Last reply
                          0
                          • C Christian Graus

                            lol - you just don't give up, do you ? I've never used CAtlArray, is it part of WTL ? How complete is it ? That is, does it offer algorithms etc, or is it merely another container of the sort I could write in an afternoon ? Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
                            C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002
                            Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002

                            C Offline
                            C Offline
                            Chris Losinger
                            wrote on last edited by
                            #14

                            Christian Graus wrote: or is it merely another container of the sort I could write in an afternoon ? For 10 points, explain how a "mere container" is a bad thing. -c


                            Please stand by

                            ThumbNailer

                            1 Reply Last reply
                            0
                            • C Christian Graus

                              Be fair - I NEVER recommend STL unless I can also answer the question, or the question has been answered. I may not have got it right, but I had a guess. And the MFC container classes are still a pile of fetid refuse. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
                              C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002
                              Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002

                              A Offline
                              A Offline
                              Alvaro Mendez
                              wrote on last edited by
                              #15

                              Christian Graus wrote: And the MFC container classes are still a pile of fetid refuse. Is there an article you can direct me to that will show what you're talking about? If not, I see it as a great opportunity to once again demonstrate your overnight article-writing abilities ;P:-). Regards, Alvaro


                              Well done is better than well said. -- Benjamin Franklin (I actually prefer medium-well.)

                              C 1 Reply Last reply
                              0
                              • A Alvaro Mendez

                                Christian Graus wrote: And the MFC container classes are still a pile of fetid refuse. Is there an article you can direct me to that will show what you're talking about? If not, I see it as a great opportunity to once again demonstrate your overnight article-writing abilities ;P:-). Regards, Alvaro


                                Well done is better than well said. -- Benjamin Franklin (I actually prefer medium-well.)

                                C Offline
                                C Offline
                                Christian Graus
                                wrote on last edited by
                                #16

                                Yes, that was a major reason I wrote my article on std::vector, to point out all the things that it does that CArray will not. CArray is a perfectly good array class ( they are not hard to write ). But how do you copy the contents of a CArray into a CList or CMap ? STL containers provide a common iterator interface. How do you sort a CArray, or shuffle it, or any other common algorithm ? The stl comes with all sorts of algorithms, and the facility to easily write more. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
                                C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002
                                Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002

                                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