Solved

CList class object as return type

Posted on 2004-04-28
4
691 Views
Last Modified: 2013-11-20
Hi,
  I need to have a CList object as return type. My code goes like this.

class EERecordVector
{
public:
      char Action;
      EERecord Record;
};

typedef CList<EERecordVector*,EERecordVector*> EERecordList;

suppose in a method like

EERecordList    CTest :: testMethod( )
{
    EERecordList   reclist;    
    EERecordVector *RecordVector =new EERecordVector();
    RecordVector->Action = 'a';
    RecordVector->Record = "test record";
    reclist.AddTail(RecordVector);   //keep on adding values like this
   return (reclist) //need to return the CList
}

I call the method as
CTest test;
EERecordList   recs = test.testMethod();

this throws error.....

can anyone suggest.......
0
Comment
Question by:abi_a
  • 3
4 Comments
 
LVL 13

Expert Comment

by:SteH
Comment Utility
Can it be CList& or CList* as well?
0
 
LVL 13

Accepted Solution

by:
SteH earned 500 total points
Comment Utility
Your prog has the problem that the list will be out of scope, when testMethod is left. reclist is only created on the stack. In the sample above you need to change this to:

EERecordList*    CTest :: testMethod( )
{
    EERecordList*   preclist;    
    EERecordVector *RecordVector =new EERecordVector();
    RecordVector->Action = 'a';
    RecordVector->Record = "test record";
    preclist->AddTail(RecordVector);   //keep on adding values like this
   return (preclist) //need to return the CList
}

don't forget to delete the returned pointer when it is not needed anymore.
0
 
LVL 13

Expert Comment

by:SteH
Comment Utility
Sorry, first line in function should read:

    EERecordList*   preclist = new EERecordList;
0
 

Author Comment

by:abi_a
Comment Utility
thanks ...it works
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

771 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

10 Experts available now in Live!

Get 1:1 Help Now