我无法将模板方法的定义放在其类之外。考虑以下来自 .h 文件的代码(剥离非必要代码以了解问题):
template <typename T> class CStyleAllocator
{
public:
    // Conversion constructor declaration
    template <typename U> CStyleAllocator(const CStyleAllocator<U>&);
};
// Attempted definition
template <typename T, typename U> CStyleAllocator<T>::CStyleAllocator(
    typename const CStyleAllocator<U>&
)
{
}
Visual C++ 2010 编译器输出此错误:
1>c:\dev\devworkspaces\dev.main\platform\cpp\memory\cstyleallocator.h(67): error C2244: 'CStyleAllocator<T>::{ctor}' : unable to match function definition to an existing declaration
1>          definition
1>          'CStyleAllocator<T>::CStyleAllocator(const CStyleAllocator<U> &)'
1>          existing declarations
1>          'CStyleAllocator<T>::CStyleAllocator(const CStyleAllocator<U> &)'
1>          'CStyleAllocator<T>::CStyleAllocator(void)'
我正在尝试定义一个依赖于 2 个泛型类型的转换构造函数。
合并类中的声明和定义是有效的:
template <typename T> class CStyleAllocator
{
public:
    template <typename U> CStyleAllocator(const CStyleAllocator<U>&) { }
};
你看到我做错了吗?