Click to See Complete Forum and Search --> : Urgent Help Me!!!
Ambili
March 29th, 1999, 05:31 AM
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.
Daren Chandisingh
March 29th, 1999, 05:52 AM
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.
Ambili
March 29th, 1999, 06:00 AM
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.
lin
March 29th, 1999, 06:15 AM
do you include the correct headfile?
Dan O'Brien
March 29th, 1999, 06:40 AM
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.
Franky Braem
March 29th, 1999, 06:43 AM
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;
Daren Chandisingh
March 29th, 1999, 07:56 AM
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".
Dan O'Brien
March 29th, 1999, 01:11 PM
How'd you get the brackets to show above? In my previous post, the brackets and everything between them was deleted from my message.
Franky Braem
March 30th, 1999, 12:14 AM
I don't know what you mean. I just typed the message in the Message Box
and posted.
Gomez Addams
March 30th, 1999, 02:17 AM
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.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.