Solved

CList class object as return type

Posted on 2004-04-28
4
699 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
[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
  • 3
4 Comments
 
LVL 13

Expert Comment

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

Accepted Solution

by:
SteH earned 500 total points
ID: 10937945
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
ID: 10937960
Sorry, first line in function should read:

    EERecordList*   preclist = new EERecordList;
0
 

Author Comment

by:abi_a
ID: 10938026
thanks ...it works
0

Featured Post

Independent Software Vendors: 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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses

628 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