help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: porting error I don't understand


From: Paul Pluzhnikov
Subject: Re: porting error I don't understand
Date: Fri, 13 May 2005 07:05:54 -0700
User-agent: Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Jumbo Shrimp, linux)

"mark" <m.somers@chem.leidenuniv.nl> writes:

> As far as I understand, the const keyword, without defining the Data
> member of the Matrix class to be "mutable", should not allow me to do
> that.

Correct. The following code demonstrates this to be true:

  struct A {
      A& operator=(const A& rhs) {
          if (&rhs != this) {
              delete this->Data;
              this->Data = rhs.Data;
              rhs.Data = 0;
          }
          return *this;
      }
    int *Data;
  };

$  g++ -dumpversion
3.3.3
$ g++ -c junk.cc
junk.cc: In member function `A& A::operator=(const A&)':
junk.cc:6: error: assignment of data-member `A::Data' in read-only structure


> But it compiles ?!

Well, you never showed us what the complete definition of 'class
Matrix' is, so there is no way for us to tell why it compiles.

> Is this a "hidden" feature of g++ or am I
> misunderstanding things again?

I don't think there is a "hidden" feature (you can test your version
with my tiny example above). Something else must be at play here.

Cheers,
-- 
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]