On Jul 25, 9:47 pm, Fabian Wein <fw...@lse.e-technik.uni-erlangen.de>
wrote:
Hi,
is there a way to call a const function from non const function?
A const function can always be called from a non-const function.
You probably meant the reverse way: "calling a non-const function from
a const function".
I have a non-const
List GetList();
and want my
bool Count() const;
implemented as
bool Foo::Count(...) const
{
return GetList().GetSize();
If your GetList() is changing the logical constness of the object,
then your Count function, which relies on GetList, should, at the
first place, be non-const.
Alternatively, if the Count function, as the name indicates, is
supposed to return just a count (or do anything that doesnot alter
logical constness of the object) then you should probably provide a
way to do this through helper functions that donot alter the logical
constness.
In other words, if you are trying to define a const function in terms
of a non-const function, you probably need to modify the design.
-N