c++ - 了解两个结构(仿函数)中 typedef 的范围

标签 c++

如果我 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/

相关文章:

c++ - 引用标的的删除

c++ - 对一对 vector 进行排序

c++ - 哪些存储类型不完整的 STL 数据结构可以用作类成员?

c++ - 不正确的插值,opengl索引的vbo,顶点结构和glsl

c++ - 在另一个线程接收的套接字上触发 EAGAIN

c++ - 仅从文件中的特定行读取数字

c++ - 是否允许递增结束迭代器?

c++ - pthreads 和 C++

c++ - 未初始化的本地字符的行为?

c++ - 为什么 std::unique_ptr::reset() 总是无异常?