Solved

using dynamic CArray -- need an array of structures

Posted on 1998-04-28
4
292 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 100 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

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

695 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