Solved

CList pointing to a structure

Posted on 1997-10-20
1
591 Views
Last Modified: 2012-08-13
Is it possible to create a CList pointing to a structure, which contains several items of CStrings??
If anyone knows the answer, possible to show an example?

Thanks a zillion
elv
0
Comment
Question by:elv
[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
1 Comment
 
LVL 5

Accepted Solution

by:
yonat earned 50 total points
ID: 1171820
Sure it is possible. Here is an example:

#include <afxtempl.h> // for CList
#include <afx.h> // for CString

struct MyStruct {
  int i;
  CString s1;
  CString s2;
};

int main()
{
  CList <MyStruct,MyStruct> myList;

  // add elements to the list
  MyStruct st;
  st.i = 17;
  st.s1 = "foo";
  st.s2 = "bar";
  myList.AddTail(st);
  // ...

  // get elements
  POSITION pos = myList.GetHeadPosition();
  while (pos != NULL)      {
    st = myList.GetNext(pos);
    // do stuff with st
  }

  return 0;
}

0

Featured Post

Technology Partners: 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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

705 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