Boost logo

Boost Users :

From: Frank Hess (frank.hess_at_[hidden])
Date: 2005-06-24 08:15:10


On Thursday 23 June 2005 05:41 pm, boost-users-request_at_[hidden]
wrote:
> Message: 9
> Date: Thu, 23 Jun 2005 17:45:25 +0100
> From: Paul Johnson <gt54-boost_at_[hidden]>
> Subject: [Boost-users] Replacing a reference with a shared_ptr?
> To: boost-users_at_[hidden]
> Message-ID: <42BAE725.2080907_at_[hidden]>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> I'm deriving from a base class in a library I use (in other words, I
>
> can't change it), and this class declares:
> > virtual string& getFilename(void) const;
> > virtual void setFilename(const string&);
>
> The base class itself doesn't declare a member to store the file name;
> it just ignores 'setFilename', and returns an empty string for
> 'getFilename'.
>
> I'd like to implement these routines, but I don't want to have a string
> reference in my derived class. If possible, I'd like to use a
> shared_ptr<string>. However, I can't see a simple way to do this.

Why are you bothering with pointers or references? Why can't you just put
a string in your class?

string myString;
virtual string& getFilename(void) const {return myString;}
virtual void setFilename(const string&) {myString = string;}

-- 
Frank



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net