Please - don't send your questions to zillions of mailing lists! Select
ONE (1) for your questions. I can't see what your question have with the
gtk+ or foxgui mailing list for example.
Anyway. When the input parameter is const, you may not change it or let a
non-const pointer or reference point to it. If the assignment was legal,
you would then be able to throw away the const, thereby allowing
assignment to the original Name object.
/Per W
On Thu, 18 Dec 2003, Maya wrote:
> Hey folks!
> I am having problems grasping the meaning of 'operator=' and copy
> constructor.
> In the following example
> namespcace jme{
> class Name{
> std::string str;
> public:
> Name(){}
> Name(const jme::Name& rhs){ this->str = rhs.str;}
> ~Name(){}
> jme::Name& operator=(const jme::Name& rhs) {
> if(this->str == rhs.str ) {
> return *this;
> }
> this->str = rhs.str;
> return *this;
> }
> };
> class Person{
> private:
> jme::Name* name;
> Init()throw(std::bad_alloc){
> try{name = new jme::Name;}
> catch(std::bad_alloc& x){ throw;}
> }
> public:
>
> Person(const jme::Name& n){
> try{ Init(); }
> catch(std::bad_alloc& x){ throw; }
> name = &n; // <<== Here is the problem
> }
> }
>
> I get an error saying: Invalid conversion 'const jme::Name*' to 'jme::Name*'
>
> If I change the parametized c'tor to jme::Person::Person(jme::Name& n) the
> constantness disapears and the program compiles, but that is not what I
> want.
> What I want if the c'tor to receive a reference to a constant jme::Name.
>
> Can someone please, help me understand what is that I am doing wrong.
> --
>
> FYI
> http://www.astro.umd.edu/~marshall/abbrev.html
>
> E-Mail Policy
> http://www.vif.com/users/escalante/Email_Policy.html
>
> * You cannot exercise your power to a point of humiliation.
> - Jean Chretien
>
> * The media's the most powerful entity on earth. They have the
> power to make the innocent guilty and to make the guilty
> innocent, and that's power.
> - Malcom X
> * "Innocent until proven guilty", no... not in Canada!!
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: IBM Linux Tutorials.
> Become an expert in LINUX or just sharpen your skills. Sign up for IBM's
> Free Linux Tutorials. Learn everything from the bash shell to sys admin.
> Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|