Re: const bei Parametern egal?
- From: Eberhard Schefold <ebab@xxxxxx>
- Date: Thu, 05 Jul 2007 11:29:34 +0200
Claus Henning schrieb/wrote:
class foo
{
void bar (const int i);
};
void foo::bar (int i)
{
}
hatte ich eigentlich eine Compiler-Fehlermeldung wegen des fehlenden const in der Definition von foo::bar() erwartet.
Nein, das ist so in Ordnung. Die entsprechende Stelle im Standard ist:
13.2 Declaration matching
[...]
— Parameter declarations that differ only in the presence or absence of const and/or volatile are
equivalent. That is, the const and volatile typespecifiers
for each parameter type are ignored
when determining which function is being declared, defined, or called. [Example:
typedef const int cInt;
int f (int);
int f (const int); // redeclaration of f(int)
int f (int) { ... } // definition of f(int)
int f (cInt) { ... } // error: redefinition of f(int)
—end example]
Only the const and volatile typespecifiers at the outermost level of the parameter type specification are ignored in this fashion; const and volatile typespecifiers buried within a parameter type specification are significant and can be used to distinguish overloaded function declarations.112) In particular, for any type T, “pointer to T,” “pointer to const T,” and “pointer to volatile T” are considered distinct parameter types, as are “reference to T,” “reference to const T,” and “reference to volatile T.”
112) When a parameter type includes a function type, such as in the case of a parameter type that is a pointer to function, the const and volatile typespecifiers at the outermost level of the parameter type specifications for the inner function type are also ignored.
.
- Follow-Ups:
- Re: const bei Parametern egal?
- From: Claus Henning
- Re: const bei Parametern egal?
- References:
- const bei Parametern egal?
- From: Claus Henning
- const bei Parametern egal?
- Prev by Date: Re: Listview & Checkbox
- Next by Date: Re: Listview & Checkbox
- Previous by thread: Re: const bei Parametern egal?
- Next by thread: Re: const bei Parametern egal?
- Index(es):
Relevant Pages
|