问题
I was just looking through implementation of non local means algorithm via google (thanks google for code search) and come across this function mirror.
template<typename T,typename U,bool N>
inline int
boundaryExpansion::helperBase<T,U,N>::mirror(const int src,
const int size,
const int last) const {
const int32 alpha(src%size);
if (alpha>=0) {
return (((src/size) & 0x00000001) != 0) ? last-alpha : alpha;
}
return (((src/size) & 0x00000001) == 0) ? -alpha-1 : size+alpha;
}
And the line I am interested in is this
const int32 alpha(src%size);
Now what is alpha here? A function or a variable? What this syntax means? Is this a variable declaration?
回答1:
This is a variable declaration. A declaration of the form:
type variablename = value;
is essentially equivalent to:
type variablename(value);
This is the case regardless of what type
is - whether it is a user-defined class or a built-in type. Note that the reverse is not always the case - the =
syntax requires that there be an accessible copy constructor.
For similar reasons, you can cast arithmetic types using the constructor syntax, as in: x = int(42.0);
回答2:
It is a variable declaration, and it is equivalent to this:
const int32 alpha = src%size;
来源:https://stackoverflow.com/questions/8686635/is-this-a-variable-or-function