相关疑难解决方法(0)

非命名空间范围内的显式特化

template<typename T>
class CConstraint
{
public:
    CConstraint()
    {
    }

    virtual ~CConstraint()
    {
    }

    template <typename TL>
    void Verify(int position, int constraints[])
    {       
    }

    template <>
    void Verify<int>(int, int[])
    {   
    }
};
Run Code Online (Sandbox Code Playgroud)

在g ++下编译它会产生以下错误:

非命名空间范围'类CConstraint'中的显式特化

在VC中,它编译得很好.任何人都可以让我知道解决方法吗?

c++ gcc templates

121
推荐指数
4
解决办法
8万
查看次数

用于模板类中模板函数显式特化的C++语法?

我的代码适用于VC9(Microsoft Visual C++ 2008 SP1)但不适用于GCC 4.2(在Mac上):

struct tag {};

template< typename T >
struct C
{   
    template< typename Tag >
    void f( T );                 // declaration only

    template<>
    inline void f< tag >( T ) {} // ERROR: explicit specialization in
};                               // non-namespace scope 'structC<T>'
Run Code Online (Sandbox Code Playgroud)

我知道GCC希望我在课外移动我的显式专业,但我无法弄清楚语法.有任何想法吗?

// the following is not correct syntax, what is?
template< typename T >
template<>
inline void C< T >::f< tag >( T ) {}
Run Code Online (Sandbox Code Playgroud)

c++ gcc templates

43
推荐指数
2
解决办法
2万
查看次数

递归可变参数模板,用于打印参数包的内容

如何创建递归可变参数模板以打印出参数包的内容?我正在尝试这个,但它无法编译:

template <typename First, typename ...Args>
std::string type_name () {
    return std::string(typeid(First).name()) + " " + type_name<Args...>();
}
std::string type_name () {
    return "";
}
Run Code Online (Sandbox Code Playgroud)

我该如何结束递归?

recursion typeid variadic-templates c++11

40
推荐指数
6
解决办法
2万
查看次数

标签 统计

c++ ×2

gcc ×2

templates ×2

c++11 ×1

recursion ×1

typeid ×1

variadic-templates ×1