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
Solved

CTypedPointerList...

Posted on 1998-04-27
3
257 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

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
xyBalance chalenge 58 96
Host to IP 7 80
wordappend challenge 8 200
Capture logon name 13 87
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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…
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.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

829 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