CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Apr 1999
    Posts
    3

    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.

  2. #2
    Join Date
    Apr 1999
    Posts
    32

    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.



  3. #3
    Join Date
    Apr 1999
    Posts
    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.

  4. #4
    Join Date
    Apr 1999
    Posts
    8

    Re: Urgent Help Me!!!



    do you include the correct headfile?

  5. #5
    Join Date
    Apr 1999
    Posts
    24

    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.

  6. #6
    Join Date
    May 1999
    Location
    Antwerp, Belgium
    Posts
    136

    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;

  7. #7
    Join Date
    Apr 1999
    Posts
    32

    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".




  8. #8
    Join Date
    Apr 1999
    Posts
    24

    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.

  9. #9
    Join Date
    May 1999
    Location
    Antwerp, Belgium
    Posts
    136

    Re: Urgent Help Me!!!



    I don't know what you mean. I just typed the message in the Message Box

    and posted.

  10. #10
    Join Date
    May 1999
    Location
    Oregon, USA
    Posts
    302

    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
  •  





Click Here to Expand Forum to Full Width

Featured