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中,它编译得很好.任何人都可以让我知道解决方法吗?
我的代码适用于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) 如何创建递归可变参数模板以打印出参数包的内容?我正在尝试这个,但它无法编译:
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)
我该如何结束递归?