我前几天遇到过这段代码:
template< class T >
T findMax(const T const * data,
const size_t const numItems) {
// Obtain the minimum value for type T
T largest =
std::numeric_limits< T >::min();
for(unsigned int i=0; i<numItems; ++i)
if (data[i] > largest)
largest = data[i];
return largest;
}
Run Code Online (Sandbox Code Playgroud)
为什么每个参数都包含两个const
s?
这没有任何有意义的理由.此外,这种显式重复的 const
限定符在C++中是非法的.代码格式不正确.
7.1.6.1 cv限定符[dcl.type.cv]
1有两个cv限定符,const和volatile.每个cv-qualifier最多只能在cvqualifier-seq中出现一次.
可以const
在C++声明中引入冗余s,但这需要"隐藏" const
在typedef-name中的先前s.在该形式中,声明将是合法的,并且将忽略冗余限定符.
归档时间: |
|
查看次数: |
250 次 |
最近记录: |