Solved

CTypedPointerList...

Posted on 1998-04-27
3
255 Views
Last Modified: 2013-11-19
I have class declarations like this:

class SomeClass
{
   //blah blah
};

class SomeOtherClass
{
protected:
   CTypedPtrList<CPtrList, CSomeClass*> m_Fields;
};

I want to add a member function getFields() that returns a reference to the m_Fields member variable. How should the the function be declared ?

This is not a homework problem.
0
Comment
Question by:footloose
3 Comments
 
LVL 23

Accepted Solution

by:
chensu earned 50 total points
ID: 1302929
class SomeOtherClass
{
protected:
   CTypedPtrList<CPtrList, CSomeClass*> m_Fields;

      CTypedPtrList<CPtrList, CSomeClass*> &getFields()
      {
            return m_Fields;
      }
};
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1302930
Also, you might find a typedef handy to make the code more readable.

eg:

class SomeClass
{
   //blah blah
};

typedef CTypedPtrList<CPtrList, CSomeClass*> CSomeClassList;

class SomeOtherClass
{
protected:
   CSomeClassList m_Fields;
public:
   CSomeCLassList& getFields() { return m_Fields; }
   const CSomeCLassList& getFields() const { return m_Fields; }
};

NOTE: I also included a const function .. its often a good idea with access functions.  In fact, sometimes you ONLY want the const version.

0
 

Author Comment

by:footloose
ID: 1302931
Thanks, guys. I will follow RONSLOW's model.
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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.

803 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