This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

calling member functions in const objects


>

Hi guys,

I came across some code of the following form:

int OuterObject::getInnerObject(const OutterObject& c)
{
  InnerObject myIO = c.getInnerObject();
  return myIO.getI();
}

which generates the following error:

testcode.cc: In method 'int OuterObject::getInnerObject(const OuterObject&)':
testcode.cc:59: passing 'const OuterObject; as 'this' argument of 'int
OuterObject::getInnerObject()' discards qualifiers

This code causes a fatal compiler error on gcc 2.95.2, but slides by with
a harmless warning on 2.81 (egcs).

I know possible solutions are to remove the 'const' qualifier or use
direct access to the class member, but is there a more elegant way around
this?

Thanks in advance for any help.
Howard


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]