Solved

CTypedPointerList...

Posted on 1998-04-27
3
250 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
Comment Utility
class SomeOtherClass
{
protected:
   CTypedPtrList<CPtrList, CSomeClass*> m_Fields;

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

Expert Comment

by:RONSLOW
Comment Utility
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
Comment Utility
Thanks, guys. I will follow RONSLOW's model.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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 tutorial demonstrates a quick way of adding group price to multiple Magento products.

728 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

15 Experts available now in Live!

Get 1:1 Help Now