Solved

CList class object as return type

Posted on 2004-04-28
4
696 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
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

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

Suggested Solutions

Title # Comments Views Activity
cat dog challenge 18 127
Folder Comparison 12 54
Define unique primary key 9 95
Making an alias 7 101
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

830 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