?
Solved

CList pointing to a structure

Posted on 1997-10-20
1
Medium Priority
?
593 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 200 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
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 learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
Suggested Courses

764 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