| re: constant member functions
srinivas reddy wrote:[color=blue]
> ...
> Can a constant member function be overloaded with its non-constant
> equivalent. I mean can void func() be overloaded with void func()
> const.[/color]
Yes.
[color=blue]
> If so what behaviour is guaranteed, how does the compiler
> resolve ambiguity?, and how could I call a specific variant?
> ...[/color]
For overloading purposes, you can think of member functions as if they
are ordinary functions with an additional implicit 'this' parameter.
When declared as a member of class 'A', method 'void func()' is
equivalent to standalone function 'void func(A* this)' and method 'void
func() const' is equivalent to standalone function 'void func(const A*
this)'. The overloading will work the same way it works for standalone
functions. For non-constant object the first version is called, for
constant objects the second version is called.
--
Best regards,
Andrey Tarasevich
Brainbench C and C++ Programming MVP |