MISRA C ++规则14-5-1:在与类型相关联的名称空间中声明的通用函数模板的名称 [英] MISRA C++ Rule 14-5-1: Name of generic function template declared in namespace associated with type

查看:55
本文介绍了MISRA C ++规则14-5-1:在与类型相关联的名称空间中声明的通用函数模板的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当名称空间为警告1573"(在与类型相关联的名称空间中声明的通用函数模板的名称")是否确实相关吗? 匿名名称空间?我测试的大多数辅助函数都放在未命名的命名空间中,这违反了上述规则.

Is Warning 1573 ("Name of generic function template declared in namespace associated with type") really relevant when the namespace is an anonymous namespace? Most of the helper functions I have for tests go in unnamed namespace and it breaks the above rule.

示例:

namespace
{
  template <typename T>
  T template_func(T arg)
  {
    return arg;
  }

  class foo {};
}

int main()
{
  return template_func(0);
}

如何满足上述要求?

推荐答案

作为示例中的状态,您可能会使用额外的命名空间,例如:

As state in their example, you might use extra namespace, something like:

namespace
{
    template< class T >
    T template_func(T arg) { return arg; }

    namespace X
    {
        class foo{};
    }
    using X::foo;
}

int main()
{
    return template_func(0);
}

这篇关于MISRA C ++规则14-5-1:在与类型相关联的名称空间中声明的通用函数模板的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆