Let us go over the basics once again:
There is only one difference (which is manifested only as a pure implementation detail) between:
void foo( int a ) { /* a can be modified in the function */ }
and
void foo( const int a ) { /* a can't be modified in the function */ }
In both cases, the parameters are passed by value (the function gets a copy). To the caller of the function, there is no semantic difference between the two. From the caller's perspective, the two functions are indistinguishable.
So the two declarations:
1 2
|
void foo( int a ) ;
void foo( const int a ) ;
|
are treated as two declarations of the same function.
If we try to provide two definitions
1 2 3
|
void foo( int a ) { /*....*/ }
void foo( const int a ) { /* ... */ }
|
we would get an error: the same function is being multiply defined.
http://coliru.stacked-crooked.com/a/2cc395d6eba4c5a9
Which was the point of my earlier question:
What can we gain by const-qualifying a parameter that is passed by value?
template < typename T > void hahaha( const T a ) { /* ... */ }
is indistinguishable from:
template < typename T > void hahaha( T a ) { /* ... */ }
=================================================
Two, in a type specifier, the position of the
const
qualifier prior to an asterisk (*) does not matter; it always applies to what is on the left of the asterisk. Kernighan and Ritchie defined the C grammar that way, and it is still that way in both C and C++.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
int i = 3 ; // int
const int c1 = 4 ; // const int
int const c2 = 4 ; // const int (alternate syntax)
int* p = &i ; // pointer to int
const int* pc1 = &c1 ; // pointer to const int
int const* pc2 = pc1 ; // pointer to const int (alternate syntax)
int* const cp1 = &i ; // const pointer to int
const int* const cpc1 = &c1 ; // const pointer to const int
int const* const cpc2 = cpc1 ; // const pointer to const int (alternate syntax)
|
Just pick one style that appeals to you, and then use it consistently.
This is an error, both the const qualifiers apply to 'int':
const int const* a = &c ; // *** error, duplicated const qualifier
This too results in the same error:
> and in my mind, the specialization should be
1 2 3
|
> template <> void hahaha<const int*>(const int const *a){
> std::cout << *a << " : " << a << std::endl;
> }
|