none
CObArray

    Question

  • Hi all,

    I wanted to do an application that can create databases and manipulates them....

    Needs to store all databases..

    I thought of doing it by using CArray  class. So I could use one CArray object to store all details of one database..Then how can I store details of many database having different no. of fields...?

    Is it possible using CObArray class?

    Whether I can store my CArray objects in CObArray objects..?

     

    I mean :

    CArray<CStoreItem, CStoreItem&> StoreItems;

    CObArray<CArray, CArray*>database ;

     

    It is showing some error.. "class CObArray may not have a template argument list".

    Someone help me please.. 

    Monday, November 21, 2011 4:21 AM

Answers

All replies

  • Don't know what framework you are trying to use there,  but it seems that the CArray class you are trying to use is not a templated class.  Do you have evidence of the contrary?
    Jose R. MCP
    Monday, November 21, 2011 5:02 AM
  • Hi Jose,

    I am using Visual Studio 2010. I have created a normal program to add details to a database using CArray class.

    It worked..

    After that I tried to modify the code so that it can be used to store details of many databases having different no. of fields.

    Thus I inserted "CObArray<CArray, CArray*>database;"

    Then the error occured...

     

    Thanks,

    Shaiby

    Monday, November 21, 2011 6:03 AM
  • Consider the CTypedPtrArray template class.

    • Marked as answer by shaiby Monday, November 21, 2011 8:19 AM
    Monday, November 21, 2011 6:53 AM
  • CObArray is an array of CObjects, so it doesn't have a template declaration.

    CObArray database;

    This means that it will work for anything derived from CObject, but you have to cast the elements before you use them.

    CArray* pArray = (CArray*)database[0];

    I think Viorel_'s suggestion is a good one.


    • Edited by Ante Meridian Monday, November 21, 2011 7:11 AM Fixed a typo.
    Monday, November 21, 2011 7:10 AM
  • On 21/11/2011 05:21, shaiby wrote:
     
    > CArray<CStoreItem, CStoreItem&> StoreItems;
    >
    > CObArray<CArray, CArray*>database ;
    >
    > It is showing some error.. "class CObArray may not have a template
    > argument list".
    >
    > Someone help me please..
    >
     
    I'd suggest to use STL container classes like std::vector.
    They are more flexible and composable than old MFC containers.
    Note that with r-value references and move semantics introduced in VC10,
    composing STL containers can also result in efficient code.
     
    Giovanni
     
    Monday, November 21, 2011 10:15 AM