Topic: const and non-const arguments to construct


Author: clamage@Eng.sun.com (Steve Clamage)
Date: 1998/02/12
Raw View
In article 1@news2.xs4all.nl, "Martijn Lievaart" <mlievaar@orion.nl> writes:
>The following code doesn't compile with any compiler I use (gcc, Sun, msvc).
>The problem is that the 'const int' is considerd the same as 'int'.
>Can anyone explain why?
>
>class A1
>{
>public:
>     A1(int p);
>     A1(const int p);
>};

The code is invalid because top-level const and volatile qualifiers
are ignored in parameter types. The two Z1 functions are not
overloaded; they are the same function.

The arguments are passed by value, and declaring a value "const" has no
effect -- you can't assign to a value, only to an object. If you could
overload the function anyway, any attempted call must be ambiguous, since
the two functions would accept exactly the same set of actual arguments.

Reference draft standard 13.1 "Overloadable declarations".

---
Steve Clamage, stephen.clamage@sun.com



[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]