如果我在某个结构(函数器)中使用某种typedef类型,则typedef的范围是否在该结构的局部?

考虑以下示例,其中我在两个单独的函子中将foo定义为intdouble。这个例子正确吗?

template <typename T>
struct firstfunctor
{
  typedef int foo;

  foo operator()(const foo& a, const foo& b)
  {
    return /*whatever*/
  }
};

template <typename T>
struct secondfunctor
{
  typedef double foo;

  foo operator()(const foo& a, const foo& b)
  {
    return /*whatever*/
  }
};

最佳答案

是的,typedef是作用域的,您分别定义成员类型firstfunctor::foosecondfunctor::foo

关于c++ - 在两个结构(函数)中了解typedef的范围,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8840501/

10-11 23:04
查看更多