部分模板的C ++ typedef
问题描述:
我需要这样做一个typedef。
i need to do a typedef like this.
template< class A, class B, class C >
class X
{
};
template< class B, class C >
typedef X< std::vector<B>, B, C > Y;
我发现它不支持C ++。
I just found that it is not supported in C++. Can someone advise me on how to achieve the same through alternative means?
感谢,
Gokul。
Thanks, Gokul.
答
如果你有一个C ++ 0x / C ++ 1x编译器,将允许与略有不同的语法(看起来好像编译器不支持此功能) :
If you have a C++0x/C++1x compiler, that will be allowed with a slightly different syntax (it seems as if compilers don't still support this feature):
template <typename B, typename C>
using Y = X< std::vector<B>, B, C >;
您可以使用其他技术,例如在模板化结构中定义一个封闭类型或者滥用继承(如果可能避免):
You can use other techniques, like defining an enclosed type in a templated struct (like Pieter suggests), or abusing inheritance (avoid if possible):
template <typename B, typename C>
class Y : public X< std::vector<B>, B, C > {};