RE: function overloading, parameter list error

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Michael Böhnisch (MichaelBhnisch_at_discussions.microsoft.com)
Date: 08/25/04


Date: Tue, 24 Aug 2004 17:47:02 -0700


"Chris Hawkins" wrote:

> I thought that functions can also differ by whether or not they are const.

Admitted, this a further cue that is used to distinguish overloads.

However, the const in "Type foo( int x, int y ) const" only indicates that
foo does not change it's object memory. The object that is returned by "foo()
const" still is assignable. I assume foo() is indeed Type::foo() ?

> If I remove the const from the foo(double, double) function everything works
> fine. That is, I can call either foo(int, int) const, foo(int, int), or
> foo(double, double). I thought explicitly casting the operands to double's
> or int's should be enough.

This behaviour startles me. To really get down to the core of your problem
further information is needed. What is the signature of the surrounding
method you are calling the assignment? Is it a const member function of the
same class foo() belongs to?

kind regards,
Michael Böhnisch



Relevant Pages

  • Re: Funky function
    ... >> It makes it possible to call this member function on a const object ... >> object may or may not be const). ... int Data; ... in the next line you try to call a function foo on MyData. ...
    (comp.lang.cpp)
  • Re: help with left-right cdecl rule
    ... This "const int * foo" also makes sense, foo is a pointer to a const ...
    (comp.lang.c)
  • Re: help with left-right cdecl rule
    ... This "const int * foo" also makes sense, foo is a pointer to a const ...
    (comp.lang.c)
  • Re: c = foo(--a) + a; ?
    ... int foo ... A compiler is allowed to notice that foo() and barreturn constants, and thus could emit code such as: ... CALL _printf ... the assignment would have to take place ...
    (comp.lang.c)
  • Re: Interesting question on const.
    ... >> Recently I attended an interview in which the question ... > letter case, int is const. ... const.c:6: error: assignment of read-only variable `a' ...
    (comp.lang.c)