Solved

CList pointing to a structure

Posted on 1997-10-20
1
572 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
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now