Why overloading is not allowed for CV qualifier.

John (Eljay) Love-Jensen eljay@adobe.com
Fri Feb 6 13:04:00 GMT 2009


Hi Mustafa,

> Why CV qualifier cannot distinguish two functions for overloading ?

The const is an implementation detail.  It is not distinguishing for pass-by-value.

You can do this:

// Header
extern void Foo(int);

// Source implementation
void Foo(int const inValue)
{
  // ...
}

And that Foo will have the correct name mangling to implement the declaration in the header.

That is NOT the situation for pass-by-reference or pass-by-pointer.

These two are different:
extern void Foo(int*);
extern void Foo(int const*);

While the pointer itself (which is pass-by-value (i.e., the pointer value)... ugh, don't think about it too hard or you'll hurt your brain) cannot use const to distinguish:
extern void Foo(int*);
extern void Foo(int* const); // Not a distinguishing overload.

HTH,
--Eljay



More information about the Gcc-help mailing list