Home

On Sep 8, 8:44 pm, er <erwann.rog...@gmail.com> wrote:
> hi,
>
> here's a piece of code and questions below. any suggestion would be
> appreciated.
>
> class Write_view{
> public:
> Write_view(Obj&,unsigned int index){/*.../*};
> void fun(...){/*...*/};//writes in portion index of Obj
>
> };
>
> class Obj{
> public:
> Write_view view(unsigned int index){
> return Write_view(*this,index)
> };
> friend class Write_view;
>
> private:
> //some data
>
> };
>
> a) should i be worried that Obj may be deleted before Write_view?
> perhaps i could make the constructor of Obj private and use a friend
> helper function to call the constructor and return a shared_ptr<Obj>.
> is that an overkill or it sounds fine?
>
> b) i'm unhappy with view(index) returning an object because i only
> need the same object no matter how often i call it on the same object.
> how about this?
>
> shared_ptr<Write_view> view(unsigned int index){
> if(count[index]==0){
> views[index]=shared_ptr<Write_view>(new
> Write_view(*this,index));
> };
> return views[index];// map<unsigned int, shared_ptr<Write_view> >
> views
> };
>
> or this?
>
> Write_view& view(unsigned int index){
> return *shared_ptr<Write_view>(new Write_view(*this,index));
> };
>
> c) is there a better way altogether?

well actually i found out that this approach is convoluted. what i do
now instead is write an impl class that does all the operations and
has operator[] return a class with a limited interface that forwards
to ptr<impl>.

previous
next

What is the solution..?
Re: Howto design my method?
Re: toprettyxml messes up with whitespaces
Re: Regular Expression Grouping
Re: Question about objects
metalizacja próżniowa
medycyna pracy Poznań
donmini katalog fajnych stron www
alergia pokarmowa
Biura Rachunkowe Lublin