[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: weird list.begin() error
From: |
Tommi Mäkitalo |
Subject: |
Re: weird list.begin() error |
Date: |
Tue, 23 Nov 2004 15:37:52 +0100 |
User-agent: |
KNode/0.7.7 |
Andre Poenitz wrote:
> Thomas <tlann@technoeclectic.com> wrote:
>>> There is no point in having a `protected' data member if you allow
>>> direct access to it via the getList() function.
>>>
>>> R'
>> ------------------------------
>> Thanks for pointing that out R'. But this is only a demo program. In
>> my actual program the pointer being returned is a const.
>
> Btw: why return a const pointer and not a const reference?
>
> Andre'
Even that is no good data-hiding. If you want to return a const reference to
something, you have to have that something. Better to define a typedef for
const_iterator and return a begin- and end-iterator:
class PlayList
{
public:
typedef list<string>::const_iterator const_iterator;
const_iterator getListBegin() const { return l.begin(); }
const_iterator getListEnd() const { return l.end(); }
private:
list<string> l;
};
That way you can redefine const_iterator if you decide to use e. g. a vector
instead of a list.
Tommi
--