This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
calling member functions in const objects
- To: gcc at gcc dot gnu dot org
- Subject: calling member functions in const objects
- From: Howard Lew <hlew at encc dot com>
- Date: Mon, 07 Aug 2000 14:23:05 -0700
- Organization: EdgeNet Communications Corporation
>
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