Solved

CList pointing to a structure

Posted on 1997-10-20
1
586 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
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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.

829 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