创建从外部作用域重新声明模板参数的typedef的负面影响
Negative side effects of creating a typedef that redeclares a template parameter from an outer scope?
有时我想从模板外部访问模板参数的类型。为此,我键入如下参数:
template<typename Vector>
class SomeAlgorithm
{
public:
typedef Vector Vector;
// ...
}
我觉得这很方便,因为我可以在客户端代码中使用相同的名称;它是显而易见和简单的。
template<typename A>
void ComputeSomething(const A& a)
{
typedef typename A::Vector Vector;
Vector v = ...
}
然而,ReSharper for C++发出警告:
typedef redeclares a template parameter from an outer scope.
对类型参数进行类型定义有什么不良的副作用吗?或者,除了为typedef使用另一个名称之外,还有更好的方法可以实现同样的效果吗?
对类型参数进行类型定义有什么不良的副作用吗?
是的,它是无效的。参数名称已经是模板作用域中的typedef名称,因此不能使用相同名称声明另一个typedef。
或者,除了为typedef使用另一个名称之外,还有更好的方法可以实现同样的效果吗?
没有。为typedef使用另一个名称。
相关文章:
- 如何将成员函数作为回调参数传递给需要"typedef-ed"自由函数指针的函数?
- typedef名称与可变模板参数名称一致时出现GCC错误
- 如何对绑定的成员方法进行typedef,然后将该类型用作模板参数
- 有没有一种方法可以使用typedef中的参数名称
- C++:显式调用模板参数的 typedef 的析构函数
- 如何在 C++ 中将 typedef 与类初始值设定项参数一起使用?
- 指向具有 2 个参数的 WINAPI 函数的 Typedef 指针
- 如何使用函数签名的 typedef 作为 std::function 的类型参数
- 如何在 C/C++ 中将 typedef 函数作为参数传递
- 如何从对象内部的 typedef 获取模板参数类型
- C 迭代器从Typedef std :: Map作为模板参数声明
- 将"typedef char IPString[17]"作为参数传递给函数
- Swig 简单类型 typedef 参数
- 如何将方法指针声明为Typedef方法参数
- c++检查模板参数的嵌套typedef以获取其标量基类型
- 以模板类型为参数的模板的typedef
- 如何用模板参数对函数指针进行typedef
- 使用模板参数的typedef不适用于g++
- 推导 typedef'd 函数指针的模板参数
- C++:使用"typedef"定义的类作为参数进行传递