?
Solved

CTypedPointerList...

Posted on 1998-04-27
3
Medium Priority
?
262 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
[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 Comments
 
LVL 23

Accepted Solution

by:
chensu earned 150 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

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

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: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

770 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