is this a variable or function

只谈情不闲聊 提交于 2019-11-30 14:23:52

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!