|
-
March 29th, 1999, 06:31 AM
#1
Urgent Help Me!!!
Hi,
I'm facing in a problem in the declaration of CList. Can you please tell me how to declare a CList object and use it.
Thanks in advance,
Ambili.
-
March 29th, 1999, 06:52 AM
#2
Re: Urgent Help Me!!!
Can you be more specific? I'm not overly familair with template classes, but I would use a CList something like this:
// first declare a CList that sores char pointers and
// returns char pointers as references to the stored items
CList <char *, char *>myList(10);
// add some char * values and store their positions in the list
POSITION p1 = myList.AddTail( (char*) "Hello " ;
POSITION p2 = myList.AddTail( (char*) "World " ;
// now I'm able to extract the values and use them
char s[50];
sprintf (s,"%s%s", myList.GetAt(p1),myList.GetAt(p2));
SetWindowText(_T(s));
I hope that is of some help to you.
-
March 29th, 1999, 07:00 AM
#3
Re: Urgent Help Me!!!
Hi,
Thanx for the information. But what i would like to know is what is the
significance of the parameters that we are passing while declaring
the CList object. But the code which i'm working now has the following
declaration:
CList m_nList;
But it gives an compilation error saying that :
" ; not found before > ".
Can you please explain this.
Thanks,
Ambili.
-
March 29th, 1999, 07:15 AM
#4
Re: Urgent Help Me!!!
do you include the correct headfile?
-
March 29th, 1999, 07:40 AM
#5
Re: Urgent Help Me!!!
The CList template container always takes two parameters as Daren showed:
CList m_nList;
CList is just a template, so it's not complete unless its 'type' is specified, in this case char*. If you are storing CFoos in the list, it would look like CList m_nList.
-
March 29th, 1999, 07:43 AM
#6
Re: Urgent Help Me!!!
CList is a template class.
The declarations is as follows :
template <class TYPE, class ARG_TYPE>
class CList : public CObject
{
...
};
TYPE is the type of the object to store.
ARG_TYPE is the type used to reference objects in the list.
When you want a list for char's then your declaration can be as follows :
CList<char *, char *> MyList;
A list of persons could be :
CList<CPerson, CPerson &> MyList;
-
March 29th, 1999, 08:56 AM
#7
Re: Urgent Help Me!!!
The declaration of a CList object requires that you
fill in the two parts of the template (because CList
is a template class). So, you can use
CList myList(10);
The first "char *" states that the list holds pointers
to char, and the second states that the list references
these as pointers to char. That might be confusing, but
that's how I understand it. The (10) is a parameter
that you can pass to the constructor that means "when this
list gets full, grow its space enough for ten more elements".
-
March 29th, 1999, 02:11 PM
#8
Re: Urgent Help Me!!!
How'd you get the brackets to show above? In my previous post, the brackets and everything between them was deleted from my message.
-
March 30th, 1999, 01:14 AM
#9
Re: Urgent Help Me!!!
I don't know what you mean. I just typed the message in the Message Box
and posted.
-
March 30th, 1999, 03:17 AM
#10
Re: Urgent Help Me!!!
I have noticed this also. Sometimes, a post appears as if it
were straight HTML (such as yours). Other times it appears
as if it has the pre tag applied. I have not figured out
drives this.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|