CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2001
    Posts
    306

    CArray arguments

    The MFC's CArray is defined as:

    template< class TYPE, class ARG_TYPE > class CArray : public CObject

    Why is there the need for two arguments? whats the purpose of the 2nd?

    thanks
    Q


  2. #2
    Join Date
    Aug 1999
    Location
    Canada
    Posts
    2,076

    Re: CArray arguments

    The second parameter is used in some member functions like :CArray::Add or CArray::SetAt.

    It specifies the type used to reference objects stored in the array. This is the reason....



  3. #3
    Join Date
    Oct 2000
    Location
    Barcelona, Spain
    Posts
    53

    Re: CArray arguments

    Hi!

    You need it for copy operations and so.
    It as simple as

    CArray<int,int&> m_YourArray;




    or your own type:


    struct t_YourType
    {
    //Your variables
    };
    CArray <t_YourType, t_YourType&> m_YourArray;



    Hope it helps,
    Toni


  4. #4
    Join Date
    Apr 1999
    Posts
    27,449

    Re: CArray arguments

    I can barely understand MSDN help for CArray as to what the second parameter is used for. This is why I use the standard STL vector<> class. No messing around -- just say what type is in the vector, and that's it. If I were you, I would also use the standard C++ collection classes (like vector, list, and map) and let MFC collections go by the wayside.

    I could never see the reason for the second argument in CArray, unless the underlying CArray code needs this argument to "help it" to do certain things. If this is the case, this is a design flaw in the CArray class.

    Regards,

    Paul McKenzie


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured