Solved

using dynamic CArray -- need an array of structures

Posted on 1998-04-28
4
274 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
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
dkremer earned 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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…
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.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now