[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

using dynamic CArray -- need an array of structures

Posted on 1998-04-28
4
Medium Priority
?
298 Views
Last Modified: 2013-11-19
I am designing a CVideoList class which will hold the an
array of this structure:

struct Video
{
   CString title;
   int have;  int want;
   int inventory_number;
   int noWaiting;
     <<a dynamic array which will hold :
   struct waitListEntry
   {
      CString waitName;
      CString contact;
   } waitList;
     >>>>>

 }

my trouble is :

1) when I compile, I find that CString is undefined
2) I understand how to use the templated class CArray

please explain:
1) which files to #include in my class header file
2) how to use dynamic CArray template class

Thank you in advance for your help.

0
Comment
Question by:ehb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
dkremer earned 300 total points
ID: 1304229
Hi.
First thing, it'll better if you derived your classes from CObject - MFC's base class.
To answer your question:
1. Include the following in StdAfx.h:
#include <afxwin.h>         // MFC core and standard components
#include <afxext.h>         // MFC extensions
#include <afxtempl.h>            // MFC Templates
2. Lets say your array variable is called m_WaitingList, and you want to set the fifth elemet, you call SetAtGrow(5, myWaitingListEntry) and if the array's upper bound is less than 5 CArray will dynamically change the size of the array for ya... :)
I think it's better to use the templatized list instead of array - it's more suitable for this case.
Check VC5 help URL : mk:@ivt:vccore/F26/D2B/S23C9.HTM
you can choose 'sample' there to see the COLLECT sample which uses all kind of data structures.
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1304230
To use a dynamic array...

CArray<data-type, arg-type>

eg.

CArray<waitListEntry,const waitListEntry &>

this means each item in the array is a 'waitListEntry' and the member function args are 'const waitListEntry&'.  For example, the template will expand to include a member function

void SetAtGrow( int nIndex, const waitListEntry& newElement );

note that 'const waitListEntry&' was used to pass an element in/out.


See the on-line help for examples (as per the answer proposed)
0
 

Author Comment

by:ehb
ID: 1304231
Could you please expound upon deriving from CObject? Can I do this for any class I want?

I took a college level OODesign/Implementation class and deriving from CObject was never mentioned.

Thank you very much for your help!

Eric

0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1304232
There is no need at all to derive from CObject - don't do it unless you really need the serialization.

You use the CArray<> (or CList<> or CMap<>) template classes.

These work equally well with non-CObject classes.

See my earlier comment .. Or better (for me) ask another question so I can ansewr it :-)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question