Link to home
Start Free TrialLog in
Avatar of footloose
footloose

asked on

CTypedPointerList...

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.
ASKER CERTIFIED SOLUTION
Avatar of chensu
chensu
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RONSLOW
RONSLOW

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.

Avatar of footloose

ASKER

Thanks, guys. I will follow RONSLOW's model.