部分模板的C ++ typedef [英] C++ typedef for partial templates
本文介绍了部分模板的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 > {};
这篇关于部分模板的C ++ typedef的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文